/    Sign up×
Community /Pin to ProfileBookmark

Regular expression problem

I am trying to break down a note in abc notation into it’s parts:
accidental (optional) ^^,^,=,_,__
note (mandatory) A-G or a-g
octave (optional) as many apostrophes or commas as necessary
multiplier (optional) integer or fraction

This is what I have to test it:

[QUOTE]

// <-accidental—–><-note–><octve><ml>< / ><dv>

var anote = /(^{0,2}|=?|_{0,2})(A-G|a-g)(‘*|,*)(d*)(/?)(d*)/;
var longnote = “__g’2/3”;
result = longnote.match(anote);
if (result != null) for (var i = 0; i < result.length; i++)
alert(i + ” ” + result[i]);
else alert(“Result longnote was null”);

var shortnote = “C”;
result = shortnote.match(anote);
if (result != null) for (var i = 0; i < result.length; i++)
alert(i + ” ” + result[i]);
else alert(“Result shortnote was null”);

[/QUOTE]


There was nothing on the error console, but the null alert came up twice. What is missing in the regular expression (or anywhere else)?

Thanks in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@wbportauthorNov 10.2010 — Never mind, I see I needed [B][[/B]A-Ga-g[B]][/B].
Copy linkTweet thisAlerts:
@wbportauthorNov 19.2010 — I am trying to create a regular expression to extract code enclosed in brackets [B][][/B] which may or may not be followed by a number or a fraction such as [Face]16, [Egbdf]1/2, or [Cab], then a "-" or space. This is what I have so far as testing:
[CODE]<html><head><title>testing</title>
<script language="javascript" type="text/javascript">
function doreg() {
var anote = /[([^]*)](d*)(/?)(d*)([- ]?/;
var longnote = "[abcde]2/3-";
result = longnote.match(anote);
if (result != null) {
for (var i = 0; i < result.length; i++)
alert(i + " ->" + result[i] + "<-");
alert("lastmatch " + RegExp.lastMatch + " Index= " + result.index + " length note= " + result[0].length); }
else alert("Result was null");
var shortnote = "[Face]";
result = shortnote.match(anote);
if (result != null) for (i = 0; i < result.length; i++)
alert(i + " ->" + result[i] + "<-");
else alert("Result shortnote was null");
alert("lastmatch " + RegExp.lastMatch + " Index= " + result.index + " length note= " + result[0].length);
}
</script>
</head>
<body><script langauge="javascript" type="text/javascript">
doreg();
</script>
</body></html>[/CODE]

I would very much appreciate any assistance on this. TIA
Copy linkTweet thisAlerts:
@wbportauthorNov 20.2010 — Never mind, this seems to get the job done:
[CODE]/[([^]]*)](d*)(/?)(d*)([- ]?)/[/CODE]
×

Success!

Help @wbport spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 1.25,
social: @webDeveloperHQ,
});

legal: ({
terms: of use,
privacy: policy
analytics: Fullres
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @dert,
tipped: article
amount: 1000 SATS,

tipper: @viney352,
tipped: article
amount: 10 SATS,
)...