Python Regex error

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

  1. kash931


    Mar 30, 2012
    Likes Received:
    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/", line 167, in findall
    return _compile(pattern, flags).findall(string)
    File "/usr/lib64/python2.4/", 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. Advertisements

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 (here). After that, you can post your question and our members will help you out.