Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Feb 03, 2009 3:15 am   
 
Ah, so that's what a non-greedy is. Thank you.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net