Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Python Regex error

Reply
Thread Tools

Python Regex error

 
 
kash931 kash931 is offline
Junior Member
Join Date: Mar 2012
Posts: 2
 
      03-30-2012
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[i]
tag = len(re.findall(b'\b(%s)\b' % dict[i], 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Python 8 09-26-2006 03:24 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Perl Misc 2 09-25-2006 03:15 AM
String Pattern Matching: regex and Python regex documentation Xah Lee Java 1 09-22-2006 07:11 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM



Advertisments