RegEx question

Tim Chase python.list at
Thu Oct 4 22:05:25 CEST 2007

>>> try @param\[(in|out)\] \w+
>> This didn't work either :(
>> The tool using this regular expression (Comment Reflower for VS2005) May be
>> broken...
> How about @param\[[i|o][n|u]t*\]\w+ ?

...if you want to accept patterns like



The regexp at the top (Adam's original reply) would be the valid 
regexp in python and matches all the tests thrown at it, assuming 
it's placed in a raw string:

   r = re.compile(r"@param\[(in|out)\] \w+")

If it's not a python regexp, this isn't really the list for the 
question, is it? ;)

However, things to try:

- sometimes the grouping parens need to be escaped with "\"

- sometimes "\w" isn't a valid character class, so use the 
long-hand variant of something like "[a-zA-Z0-9_]]

- sometimes the "+" is escaped with a "\"

- if you don't use raw strings, you'll need to escape your "\" 
characters, making each instance "\\"



More information about the Python-list mailing list