[Tutor] regular expression woes ..
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 6 Aug 2001 11:02:58 +0100
> Does anybody know why when I try...
>
> >>> pat = re.compile('_.*' | '\..*')
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in ?
> pat = re.compile('_.*' | '\..*')
> TypeError: unsupported operand type(s) for |
Coz the re function takes a single RE as a string.
You are trying to take the bitwise OR of two strings
and pass the result. Bitwise ORs don't work with
strings... You need to form the whole RE as a single string.
"_.*|\..*"
OR maybe
"(_.*)|(\..*)"
depending onm exactly what you want.
BTW. Somebody has put on the web a really nice RE syntax
checker written in Python and Tkinter. You might want to
do a search and see if you can pick it up...
> >>> pat = re.compile(('_.*') | ('\..*'))
I suspect this is the correct one if you just wrap it all
as a string...
Alan G