help regarding re.search

Sagar Neve nevesagar at gmail.com
Wed Sep 14 23:33:59 EDT 2011


If A in B:
does nt seem to be working.
Am I missing something here.

-$agar
On Sep 15, 2011 7:25 AM, "Chris Rebert" <clp2 at rebertia.com> wrote:
> On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve <nevesagar at gmail.com> wrote:
>> Hi,
>> I have a small program where I want to do just a small regex operation.
>> I want to see if value of a variable 'A' is present in an another
variable
>> 'B'.  The below code works fine but as soon as the variable 'A' has some
>> string including a dot it fails.
>
> There's no need to use regexes at all! Just do:
> if A in B:
> # do something
>
>> for example say:
>> B="xxxxyyyydpkg.ipazzzzz
>> The code works fine  when A="dpkg"
>> however the code does not work when A="dpkg.ipa"
>
> Right, because period is a regex metacharacter. To have it treated as
> a literal character to match, escape it:
> http://docs.python.org/library/re.html#re.escape
>
> Cheers,
> Chris
> --
> http://rebertia.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110915/6415dd0c/attachment-0001.html>


More information about the Python-list mailing list