Regular expressions
Dennis Reinhardt
DennisR at dair.com
Sat Oct 25 20:07:29 EDT 2003
> re.search("[yipee]*", line):
>
> This will treat yipee as a string correct? I want it to treat yipee as a
> variable and perform the different combinations on whatever is inside the
> variable.
You don't want square bracket. You want parenthesis. But this is not the
only problem. Simply replacing the square brackets with parenthesis does
not treat yipee as a variable. The
"%s" % variable
idiom will do this
Also, it is not clear why the sample line ends with a colon. I took it off
The "*" will match on no occurrences and I suspect you want to match on one
or more. I replaced "*" with "+".
I think you want:
re.search("(%s)+" % yipee, line)
--
Dennis Reinhardt
DennisR at dair.com http://www.spamai.com?ng_python
More information about the Python-list
mailing list