[BangPypers] Regular Expressions
Nitin Kumar
nitin.nitp at gmail.com
Tue Mar 22 08:55:35 CET 2011
use this way
r'(/|\\)cmd\.com$'
Its raw string stuff which i guess you are missing out.
Nitin K
On Wed, Mar 16, 2011 at 11:27 PM, Santhosh Edukulla <
santhosh.edukulla at gmail.com> wrote:
> Hi All,
>
> I have a list of regular expressions under a file(EX: inp.txt). Then, I
> have
> another file (EX: search.txt).The task is that i have to read the list of
> regular expressions from the inp.txt and then search for the same in
> "search.txt" and output the matched string.
>
> Iam using python *"re" *module to do this.
>
> This works except for few regular expressions below.
>
> *a = '(/|\\)cmd\.com$'*
>
> 1.
> When i read the regular expression above from the file to a variable *(EX:
> a)*. as below
> EX:
> *a=open('inp.txt','r').readlines()[0]*
>
> Iam getting a different regular expresson as *'(/|\\\\)cmd\.com$'*
>
> 2. Instead when i use *a.encode('string-escape')*, iam getting the output
> for a as * '(/|\)cmd\.com$' *So when used like this, re.compile() statement
> gives an error
>
>
> Any idea to solve this.
>
> Thx,
> Santhosh
>
>
> Thx,
> Santhosh
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
Nitin K
More information about the BangPypers
mailing list