|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Tue Feb 03, 2009 1:20 am
Regex: Match Completes before the end [Solved] |
This is my fault, not CMUDs, but that doesn't get me any closer to solving it.
Here's the regex:
Code: |
^You (sit|rest)(?: (?:down|in|on) (?:[\w\-' ]+)( and rest)?)?\.$
|
With the following phrase:
You sit down at a planning table and rest.
%1=sit
and
%2=null
the "and rest" is matched by my previous regex and thus it never gets to it. The problem is that the objects I can sit on can vary and I'm not sure how many words they could be, not to mention if they're not as many as the max amount of words, then "and rest" will be absorbed anyways. Any idea on how to fix this? Right now I'm thinking I may have to make %2 be the (?:[\w\-' ]+) and use that find function to see if the word "rest" is in there (by itself, to avoid something like "restaurant" matching. |
|
_________________ Listen to my Guitar - If you like it, listen to more
Last edited by chamenas on Tue Feb 03, 2009 3:33 am; edited 1 time in total |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Feb 03, 2009 2:05 am |
Stick a question mark after the troublesome plus, giving you a non-greedy capture. You can read more about those on regular-expressions.info.
|
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Tue Feb 03, 2009 3:15 am |
Ah, so that's what a non-greedy is. Thank you.
|
|
|
|
|
|