[Tutor] Regex help
mi.janssen at gmail.com
Mon Aug 28 11:50:55 CEST 2006
On 8/26/06, William O'Higgins Witteman <hmm at woolgathering.cx> wrote:
> I want a case-insensitive, verbose pattern. I have a long-ish list of
> match criteria (about a dozen distinct cases), which should be all "or",
> so I won't need to be clever with precedence.
BTW I find it easier not to use re.VERBOSE which ignores any
whitespace. Instead I use the silent-string-continuation feature to
put my comments in the right place:
regexp_str = ('one' # matches one
'|two' # matches two
'|three' # matches three
there must be no commas: I don't want a tuple but rather the strings
to be concatenated within the brackets. But then:
regexp_tuple = ('one', 'two', 'three')
regexp_str = '|'.join(regexp_tuple)
This way you do not need to manually sets the "|" specialchars.
The python modul /usr/lib/python2.4/tokenize.py comes with lots of
examples, especially with OR'ed pattterns.
More information about the Tutor