[Tutor] Regular Expression help - parsing AppleScript Lists as Strings
Andrew Wu
andrewwu at gmail.com
Thu Nov 1 17:20:53 CET 2007
Ah - thanks for the correction! I missed the extra grouping and the
extra spacing ... doh! Sorry about the HTML-formatted e-mail ...
Thanks also for the pyparsing variant as well - I didn't know the
module existed before!
Andrew
On 11/1/07, Kent Johnson <kent37 at tds.net> wrote:
> Andrew Wu wrote:
>
> > pattern3 = '''
> > ^{
> > (
> > %s
> > | {%s} # Possible to have 1 level of nested lists
> > ,?)* # Items are comma-delimited, except for the last item
> > }$
> > ''' % (pattern2, pattern2)
>
> The above doesn't allow comma after the first instance of pattern2 and
> it doesn't allow space after either instance. Here is a version that
> passes your tests:
>
> pattern3 = '''
> ^{
> (
> (%s
> | {%s}) # Possible to have 1 level of nested lists
> ,?\s*)* # Items are comma-delimited, except for the last item
> }$
> ''' % (pattern2, pattern2)
>
> You might want to look at doing this with pyparsing, I think it will
> make it easier to get the data out vs just recognizing the correct pattern.
>
> Kent
>
> PS Please post in plain text, not HTML.
>
More information about the Tutor
mailing list