December 5th, 2009, 12:16 AM
Simple Regex Not Working?
Basically, it should match anything from "i live in tucson" to "my favorite food is cheese"... with the (\w+) being the only values saved in a compiled array. I'm using Python, meaning I am going to save this into an array... but I only want to keep the two (\w+)'s in it. What am I doing wrong? I've tried everything!
lalala = "my favorite food is cheese"
pattern = re.compile('(i|my|my\s+own|mine)\s+(\w+)\s+(in|at|is|are|am|will\s+be)\s+(\w+)')
wildcard = pattern.match(lalala).groups()
December 7th, 2009, 03:22 PM
Your regexp matches "my" then any word, then "is" then any word.
You have TWO words between "my" and "is" in your test.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.