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
haiku
Wanderer


Joined: 19 Nov 2004
Posts: 70

PostPosted: Sat Sep 15, 2007 4:07 am   

quick pattern matching question
 
here's the current trigger pattern:
Code:
^~[{| } %d %w %w {L| } ~] (%w) %s (%d)/(%d) %s %d/%d %s %d/%d %s %d$


It does the job nicely.

That only works though, if I'm introduced to the person.
Here's some sample mud text:

Code:

[ 28 Mon Trl   ] Groob                 387/411   315/315   109/144      3020373
[ 10 Mag Hum   ] a female human          64/95    14/197     75/75       145968


What I thought would work was this:

Code:
^~[{| } %d %w %w {L| } ~] {(%w)| a (%w) %w} %s (%d)/(%d) %s %d/%d %s %d/%d %s %d$


I wanted to grab that second word - in this case female - such that I could target them like I target Groob.

The code seems to compile, and it doesn't throw an error message, but it does nothing when I do a
Code:
#SHOW %1 %2 %3 %4

, whereas my current trigger will show Groob 387 411 with the same trigger.

Personally, I think that the
Code:
 {(%w)| a (%w) %w}
part should work, but it obviously isn't. Any ideas?
Reply with quote
DeReP
Adept


Joined: 14 Jun 2003
Posts: 222
Location: Chile

PostPosted: Sat Sep 15, 2007 6:39 am   
 
How about
Code:
^~[{| }%d %w %w {L| } ~]%s{(%w)|a%s(%w)%s%w}%s(%d)/(%d)%s%d/%d%s%d/%d%s%d$

Perhaphs leaving that space before the "a" and after the "]" (making it a double space) would make your trigger not to fire at all.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Sep 15, 2007 1:41 pm   
 
Use a fixed width pattern instead. Then parse it with %trim, %word, and %numwords.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Sep 15, 2007 1:49 pm   
 
Wildcards don't work inside the {one|two} syntax. You can use a regex instead.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sat Sep 15, 2007 6:38 pm   
 
Code:
^\[ *\d+ \w+ \w+ +L? \] (?:a )?(\w+) [\w ]+ (\d+)/(\d+) +\d+/\d+ +\d+/\d+ +\d+$

Regex.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Sep 16, 2007 9:09 am   
 
One tiny change to get the captures working properly:

Code:
^\[ *\d+ \w+ \w+ +L? \] (?:a )?(\w+) [\a ]+(\d+)/(\d+) +\d+/\d+ +\d+/\d+ +\d+$


This also didn't actually match your test lines, haiku, because they have a space at the end. You might need to add that in.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sun Sep 16, 2007 3:32 pm   
 
Fang: What's \a in CMud? My cheat sheet tells me it's a bell/alarm character, and obviously it's not functioning like that.

Although my original pattern works fine, too, on both examples. Wink At least according to the test trigger box as well as the RegEx Coach. (I didn't include space at the end based on the original trigger which apparently worked.)
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sun Sep 16, 2007 3:45 pm   
 
I think it's a confused %a that doesn't convert to \a (should be \w or [a-z]), but maybe CMUD doesn't use the standard \a as the bell character?
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sun Sep 16, 2007 4:51 pm   
 
I tried the \a in the pattern matcher, and it was functioning like [A-z], so not quite like %a and not quite like \w, but I see what he was getting at now--if the name line runs long and you don't get a space between it and the first set of numbers, then you'd need that pattern.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Sep 16, 2007 6:03 pm   
 
\a is [A-z] like you say. %w is \a+. Don't ask me why %w and %a are the wrong way round - they just are.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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