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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
manbat
Novice


Joined: 21 Mar 2009
Posts: 35

PostPosted: Mon Oct 19, 2009 12:43 am   

Regex pattern not matching
 
Code:
<trigger name="AGhunt" priority="3300" regex="true" id="298">
  <pattern>{the|a}\w? \w*?\s?@AGhunttarget\s?\w*?, {right here|nearby to the}\s?(\w+?)\.$</pattern>
  <value>#T+ AGhuntbad
#T+ AGcombatless
#T+ AGcombatadd
#T+ AGmain
#T- AGwalkchecklook
#IF (!%1) { kill @{AGkillsteal}.@AGhunttarget }
{ c 'holy flame' %1 @{AGkillsteal}.@AGhunttarget }
#T- AGhunt</value>
</trigger>


My pattern should be something like
Code:
a small minotaur, right here.

or
Code:
a minotaur slave, nearby to the west.


However for some reason I can't figure this out....

{the|a} - match either "the" or "a"
\w? - allow to match "them" or "an"
\w*? - allow to match anything that starts with a word character, and keep going until it hits a space or digit character
\s? - allow to match a space
@AGhunttarget - a variable
{right here|nearby to the} - match either "right here" or "nearby to the"
\s? - allow to match a space
(\w+?) - allow to match a word like "west" and then put it into %1
\.$ - match a period and then end of line

Do I have that right?
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Mon Oct 19, 2009 12:55 am   
 
(?:them?|an?) (?:\w+ )?@AGhunttarget(?: \w+)?, (?:right here|nearby to the \w+)\.

(?:
them? to match 'the' or 'them'.
or
an? to match 'a' or 'an'.
)

(?:\w+ )? to match a word with a space after it or nothing at all.

@AGhunttarget for your target.

(?: \w+)? to match a space with a word after it or nothing at all.

(?:
right here
or
nearby to the \w+
)

\. period.
Reply with quote
manbat
Novice


Joined: 21 Mar 2009
Posts: 35

PostPosted: Mon Oct 19, 2009 1:07 am   
 
Interesting.. where is "(?:" documented? I assume putting a ? following a character makes that character optional?
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Mon Oct 19, 2009 1:12 am   
 
manbat wrote:
Interesting.. where is "(?:" documented? I assume putting a ? following a character makes that character optional?


In the documentation for #regex. (?:) is the same as () except it doesn't store the expression in the %1-99 variables. As for ?, from the help file: ? matches zero or one of the previous pattern. In example:

an? will match a or an.

(?:an)? will match an or nothing.
Reply with quote
manbat
Novice


Joined: 21 Mar 2009
Posts: 35

PostPosted: Mon Oct 19, 2009 1:16 am   
 
Ahhh... I get it now.... Thanks! I saw that there but didn't understand how it would be applied.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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