problem with regex

Roy Smith roy at panix.com
Mon Apr 28 09:03:57 EDT 2014


In article <caeba811-441e-42a0-9b2b-c743205b1f82 at googlegroups.com>,
 dimmaim at gmail.com wrote:

> i want to find a specific urls from a txt file but i have some issus. First 
> when i take just two lines from the file with copy paste and assign it to a 
> variable like this and it works only with triple quotes
>  
> test='''<long string elided>'''
[...]
> but if a take those lines and save it into a txt file like the original is 
> without the quotes [it doesn't work]

I suspect this has nothing to do with regular expressions, but it's just 
about string management.

The first thing you want to do is verify that the text you are reading 
in from the file is the same as the text you have in triple quotes.  So, 
write a program like this:

test='''<long string elided>'''

datafile=open('a.txt','r')
data_array=''
for line in datafile:
    data_array=data_array+line

print test == data_array

If that prints True, then you've got the same text in both cases (and 
you can go on to looking for other problems).  I suspect it will print 
False, though.  So, now your task is to figure out where those two 
strings differ.  Maybe something like:

for c1, c2 in zip(test, data_array):
    print c1 == c2, repr(c1), repr(c2)

and look for the first place they're not the same.  Hopefully that will 
give you a clue what's going wrong.



More information about the Python-list mailing list