Regex help needed

rh0dium sklass at pointcircle.com
Tue Jan 10 17:39:47 EST 2006


Paul McGuire wrote:

> ident = Combine( Word(alpha,alphanums+"_") + LPAR + RPAR )

This will only work for a word with a parentheses ( ie.  somefunction()
)

> If you *really* want everything on the first line to be the ident, try this:
>
> ident = Word(alpha,alphanums+"_") + restOfLine
> or
> ident = Combine( Word(alpha,alphanums+"_") + restOfLine )

This nicely grabs the "\r"..  How can I get around it?

> Now the next step is to assign field names to the results:
>
> dataFormat = ident.setResultsName("ident") + ( dblQuotedString |
> quoteList ).setResultsName("contents")

This is super cool!!

So let's take this for example

test= 'fprintf( outFile "leSetInstSelectable( t )\n" )\r\n ("test"
"test1" "foo aasdfasdf"\r\n "newline" "test2")\r\n'

Now I want the ident to pull out 'fprintf( outFile
"leSetInstSelectable( t )\n" )' so I tried to do this?

    ident = Forward()
    ident << Group( Word(alphas,alphanums) + LPAR + ZeroOrMore(
dblQuotedString | ident | Word(alphas,alphanums) ) + RPAR)

Borrowing from the example listed previously.  But it bombs out cause
it wants a ")"  but it has one..  Forward() ROCKS!!

Also how does it know to do this for just the first line?  It would
seem that this will work for every line - No?




More information about the Python-list mailing list