regex query

David Wilson dw at botanicus.net
Fri Jun 11 14:18:06 EDT 2004


On Fri, Jun 11, 2004 at 10:48:14PM +0530, km wrote:

> how do i include variable as a part of the regex string ? - i mean
> variable interpolation. like : 

> import re
> str = "abc"
> p = re.compile('str')  # defeats the purpose - literal string 'str'

Do you mean something like:

    literal = raw_input('Arbitrary string: ')
    regex = re.compile('someregex' + re.escape(literal) + 'moreregex')


David.

-- 
"The significant problems we face cannot be solved at the same level of
thinking we were at when we created them."
    -- Albert Einstein




More information about the Python-list mailing list