[BangPypers] Regular Expressions
Senthil Kumaran
orsenthil at gmail.com
Thu Mar 17 03:36:48 CET 2011
On Wed, Mar 16, 2011 at 11:27:24PM +0530, Santhosh Edukulla wrote:
> 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$'*
I think, you were trying this in the interpreter and you were using
the interpreter to check the regex output. I got tripped by it too,
and had to take help from IRC.
Look at this session:
>>> f = open('inp.txt')
>>> c = f.read()
>>> c
'(/|\\\\)cmd\\.com$\n'
>>> # That is because it is doing a repr(c)
>>> # But do a print, you will see
>>> print c
(/|\\)cmd\.com$
Does this help?
--
Senthil
More information about the BangPypers
mailing list