<div dir="ltr"><div>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</div><div><br></div><div><div>&quot;<span style="font-size:12.8px">o4l8cdefg</span>&quot; =&gt; string code;</div><div>string matches[0];</div><div>&quot;((o)([0-9]+)|([abcdefg])(1|2|<wbr>4|8|16)?|(l)([0-9]+))&quot; =&gt; string pattern;</div><div><br></div><div>for(0 =&gt; int i; i &lt; code.length(); )</div><div>{</div><div>    if(RegEx.match(pattern, code.substring(i), matches))</div><div>    {</div><div>        if(matches[2] == &quot;o&quot;)</div><div>            &lt;&lt;&lt; &quot;octave:&quot;, matches[3] &gt;&gt;&gt;;</div><div>        else if(matches[4] == &quot;a&quot;)</div><div>            &lt;&lt;&lt; &quot;a&quot; &gt;&gt;&gt;;</div><div>        // etc.</div><div>        </div><div>        matches[0].length() +=&gt; i;</div><div>    }</div><div>    else</div><div>    {</div><div>        &lt;&lt;&lt; &quot;invalid code&quot; &gt;&gt;&gt;;</div><div>        break;</div><div>    }</div><div>}</div></div><div><br></div><div>I dont know anything about MML so I dont know what the final regex would look like. </div><div><br></div><div>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. </div><div><br></div><div><div>for(0 =&gt; int i; i &lt; code.length(); )</div><div>{</div></div><div>    int c = code.charAt(i);</div><div>    if(c == &#39;o&#39;)</div><div>    {</div><div>         // look for number</div><div>    }</div><div>    else if(c == &#39;a&#39; || c == &#39;b&#39; || ... )</div><div>    {</div><div>         // see if number follows</div><div>    }</div><div>}</div><div><br></div><div>spencer</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 6, 2016 at 6:32 PM, Colton Hill <span dir="ltr">&lt;<a href="mailto:colton-hill2014@hotmail.com" target="_blank">colton-hill2014@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I also want to make sure I have a customizable play function that will<br>
handle my playing. Here&#39;s the code I&#39;ve been using for my current mml<br>
parser in chuck, actually does take a code string and a play function,<br>
and operates well. Only issue is including doesn&#39;t work... So have a test.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 9/6/2016 3:33 AM, Hans Åberg wrote:<br>
&gt;&gt; On 5 Sep 2016, at 23:16, Colton Hill &lt;<a href="mailto:colton-hill2014@hotmail.com">colton-hill2014@hotmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I know regular expressions syntax, but I really don&#39;t know how I would<br>
&gt;&gt; manage to make an mml parser that actually works. Turn o4l8cdefg into<br>
&gt;&gt; octave 4, length 8, and c d e f g notes with an 8th note length since no<br>
&gt;&gt; length is specified. Then there&#39;s c4., which is c4^c8... Just bla…<br>
&gt; There are free MML parsers in C out there. Linking to ChucK, which is written in C++, might be a way.<br>
&gt;<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.<wbr>edu/mailman/listinfo/chuck-<wbr>users</a><br>
<br>
</div></div><br>______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.<wbr>edu/mailman/listinfo/chuck-<wbr>users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="font-family:arial;font-size:small"><div>Spencer Salazar<br></div><div>Doctoral Candidate</div><div>Center for Computer Research in Music and Acoustics</div><div>Stanford University</div><div><br></div><div><a href="mailto:spencer@ccrma.stanford.edu" target="_blank">spencer@ccrma.stanford.edu</a></div><div></div><div>+1 831.277.4654<br></div><div><a href="https://ccrma.stanford.edu/~spencer/" style="color:rgb(17,85,204)" target="_blank">https://ccrma.stanford.edu/~spencer/</a><br></div><div><br></div></div></div></div></div></div></div></div></div></div>
</div>