Python Regex error

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

  1. kash931

    kash931

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

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:
    958
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    2,033
    Ant...
    Nov 6, 2003
  3. a_c_Attlee@yahoo.com

    Java regex imposture re: Perl regex compatibility

    a_c_Attlee@yahoo.com, May 5, 2005, in forum: Java
    Replies:
    2
    Views:
    787
    gimme_this_gimme_that@yahoo.com
    May 6, 2005
  4. Xah Lee
    Replies:
    1
    Views:
    1,182
    Ilias Lazaridis
    Sep 22, 2006
  5. Xah Lee
    Replies:
    8
    Views:
    692
    Ilias Lazaridis
    Sep 26, 2006
  6. seberino@spawar.navy.mil
    Replies:
    3
    Views:
    1,112
    Reedick, Andrew
    Jul 1, 2008
  7. RolfK
    Replies:
    1
    Views:
    2,185
    Martin Honnen
    Jun 7, 2009
  8. Xah Lee
    Replies:
    2
    Views:
    406
    Xah Lee
    Sep 25, 2006
Loading...