Python Regex error

Joined
Mar 30, 2012
Messages
1
Reaction score
0
Hi guys,

I am new to python. I am trying to find out an exact match using the following code(looped)

def _match(dict, keyword):
for i in range(0,len(dict)):
#indicators = dict
tag = len(re.findall(b'\b(%s)\b' % dict, phrase.lower(), re.IGNORECASE))
#print tag
if tag > 0:
return '1';
return '0'

the above function is used to read an input file line by and ping it against the phrase to find exact match. It worked ok with a an example i.e. one line, but when it came to a csv where i have 3 columns and n rows, it is showing this error

Traceback (most recent call last):
File "<stdin>", line 8, in ?
File "<stdin>", line 4, in _match
File "/usr/lib64/python2.4/sre.py", line 167, in findall
return _compile(pattern, flags).findall(string)
File "/usr/lib64/python2.4/sre.py", line 227, in _compile
raise error, v # invalid expression
sre_constants.error: unknown extension

Can someone give a quick solutions as why this is happening and what should be done. PLS KINDA URGENT!!

the code i used to read in the phrase file is given below:
for line in kw:
out_str = line.strip()
cols = line.strip().split(',')
terms = cols[2]
match = _match(temp, terms)
out_str = out_str + ',' + match
print out_str
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top