&gt;Hopefully this is useful to someone else.<div>It will be :)</div><div><br></div><div>Thanks,</div><div>Pedro<br><br><div class="gmail_quote">On Mon, Nov 29, 2010 at 4:46 AM, Chris McCormick <span dir="ltr">&lt;<a href="mailto:chris@mccormick.cx">chris@mccormick.cx</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi,<br>
<br>
Here is how you can parse Pd patches into rows of atoms in three languages using regular expressions:<br>
<br>
/*** Javascript ***/<br>
<br>
        var lines_re = new RegExp(&quot;(#((.|\r|\n)*?)[^\\\\])\r{0,1}\n{0,1};\r{0,1}\n&quot;, &quot;gi&quot;);<br>
        for (pdline = lines_re.exec(patchtext)) {<br>
                var atoms = pdline[1].split(/ |\r\n?|\n/);<br>
        }<br>
<br>
### Python ###<br>
<br>
        lines_re = re.compile(&quot;(#(.*?)[^\\\])\r{0,1}\n{0,1};\r{0,1}\n&quot;, re.MULTILINE | re.DOTALL)<br>
        split_re = re.compile(&quot; |\r\n?|\n&quot;, re.MULTILINE)<br>
        for found in lines_re.finditer(patch):<br>
                line = found.group(1)<br>
                atoms = split_re.split(line)<br>
<br>
/*** Java ***/<br>
<br>
        private static final String line_re = &quot;(#((.|\r|\n)*?)[^\\\\])\r{0,1}\n{0,1};\r{0,1}\n&quot;;<br>
        private static final String token_re = &quot; |\r\n?|\n&quot;;<br>
<br>
        Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE);<br>
        Pattern token_pattern = Pattern.compile(token_re, Pattern.MULTILINE);<br>
        Matcher matcher = pattern.matcher(patchtext);<br>
        ArrayList&lt;String[]&gt; atomlines = new ArrayList&lt;String[]&gt;();<br>
        while (matcher.find()) {<br>
                String[] s = token_pattern.split(matcher.group(1));<br>
                atomlines.add(token_pattern.split(matcher.group(1)));<br>
        }<br>
<br>
Also here is a regular expression for matching dollar args:<br>
<br>
        /(?:\\{0,1}\$)(\d+)/g;<br>
<br>
Hopefully this is useful to someone else.<br>
<br>
Cheers,<br>
<br>
Chris.<br>
<br>
-------------------<br>
<a href="http://mccormick.cx" target="_blank">http://mccormick.cx</a><br>
<br>
_______________________________________________<br>
<a href="mailto:Pd-list@iem.at">Pd-list@iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -&gt; <a href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Pedro Lopes (MSc)<br>contact: <a href="mailto:pedro.lopes@ist.utl.pt" target="_blank">pedro.lopes@ist.utl.pt</a><br>website: <a href="http://web.ist.utl.pt/Pedro.Lopes" target="_blank">http://web.ist.utl.pt/Pedro.Lopes</a> <br>


</div>