[Tutor] regular expression woes ..

Bruce Sass bsass@freenet.edmonton.ab.ca
Sun, 5 Aug 2001 22:54:33 -0600 (MDT)


On Sun, 5 Aug 2001, Israel C. Evans wrote:
> 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 |
>
> I get the error that I do?

Because you can't "or" two strings, if you could you would be passing
the result onto re.compile.  Is this what you are after...

>>> import re
>>> pat = re.compile("_.*|\..*")
>>>

[you may want to re-read the bit about using raw strings for regular
expressions]

<...>
>  I've also tried
> >>> pat1 = re.compile('_.*')
> >>> pat2 = re.compile('\..*')
> >>> allpat = re.compile(pat1 | pat2)
>
> ....same error as before...

...because you are doing the same as before,
trying to "or" two strings.


- Bruce