Difference in regex between Python and Rubular?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-05-09T22:24:31Z Indexed on 2010/05/09 22:28 UTC
Read the original article Hit count: 287

Filed under:
|
|

In Rubular, I have created a regular expression:

(Prerequisite|Recommended): (\w|-| )*

It matches the bolded:

Recommended: good comfort level with computers and some of the arts.

Summer. 2 credits. Prerequisite: pre-freshman standing or permission of instructor. Credit may not be applied toward engineering degree. S-U grades only.

Here is a use of the regex in Python:

note_re = re.compile(r'(Prerequisite|Recommended): (\w|-| )*', re.IGNORECASE)

def prereqs_of_note(note):
    match = note_re.match(note)
    if not match:
        return None
    return match.group(0) 

Unfortunately, the code returns None instead of a match:

>>> import prereqs

>>> result  = prereqs.prereqs_of_note("Summer. 2 credits. Prerequisite: pre-fres
hman standing or permission of instructor. Credit may not be applied toward engi
neering degree. S-U grades only.")

>>> print result
None

What am I doing wrong here?

© Stack Overflow or respective owner

Related posts about python

Related posts about rubular