I dont think you can use regex to match a whole expression like that but you can use it to pick off bits and pieces. Just make a regex that matches all of the possible commands + options and run that through, advancing the string position each time. Eg
"o4l8cdefg" => string code;
string matches[0];
"((o)([0-9]+)|([abcdefg])(1|2|4|8|16)?|(l)([0-9]+))" => string pattern;
for(0 => int i; i < code.length(); )
{
if(RegEx.match(pattern, code.substring(i), matches))
{
if(matches[2] == "o")
<<< "octave:", matches[3] >>>;
else if(matches[4] == "a")
<<< "a" >>>;
// etc.
matches[0].length() +=> i;
}
else
{
<<< "invalid code" >>>;
break;
}
}
I dont know anything about MML so I dont know what the final regex would look like.
Another option is to just go through the string iteratively and look at each character one at a time. If whitespace is undesirable StringTokenizer might be hurting more than helping here.
for(0 => int i; i < code.length(); )
{
int c = code.charAt(i);
if(c == 'o')
{
// look for number
}
else if(c == 'a' || c == 'b' || ... )
{
// see if number follows
}
}
spencer