Python Regex error

Discussion in 'Software' 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. ConTactMe

    matches regex?

    ConTactMe, Dec 15, 2003, in forum: Computer Support
    Replies:
    1
    Views:
    2,635
    Livewire
    Dec 15, 2003
  2. gregfaulk@gmail.com

    http inspection exclusion by regex

    gregfaulk@gmail.com, Mar 27, 2007, in forum: Cisco
    Replies:
    0
    Views:
    427
    gregfaulk@gmail.com
    Mar 27, 2007
  3. Indo Geek

    Procmail Regex

    Indo Geek, May 11, 2007, in forum: Computer Support
    Replies:
    2
    Views:
    679
  4. Bob Larter is Lionel Lauer - Look it up.

    Re: Colour recovery [Was: Regex and more! [Was: Crossword puzzle]]

    Bob Larter is Lionel Lauer - Look it up., Nov 11, 2009, in forum: Digital Photography
    Replies:
    4
    Views:
    448
    Bob Larter
    Nov 11, 2009
  5. partyin
    Replies:
    0
    Views:
    1,017
    partyin
    Feb 21, 2012
Loading...

Share This Page