Python Regex error

Discussion in 'Python' started by kash931, Mar 30, 2012.

  1. kash931

    kash931

    Joined:
    Mar 30, 2012
    Messages:
    1
    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
    kash931, Mar 30, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    688
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Xah Lee
    Replies:
    1
    Views:
    927
    Ilias Lazaridis
    Sep 22, 2006
  3. Xah Lee
    Replies:
    8
    Views:
    455
    Ilias Lazaridis
    Sep 26, 2006
  4. seberino@spawar.navy.mil
    Replies:
    3
    Views:
    726
    Reedick, Andrew
    Jul 1, 2008
  5. Xah Lee
    Replies:
    2
    Views:
    209
    Xah Lee
    Sep 25, 2006
Loading...

Share This Page