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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
rholcomb3
Newbie


Joined: 22 Aug 2007
Posts: 4

PostPosted: Wed Aug 22, 2007 2:14 am   

REGEX isn't evaluating
 
Hi everyone,

I've searched through these forums, and haven't managed to find my answer here, so here goes with my own post.

I have a perl regex set up as a triger that goes as follows:

^ \ (\a+)\s*\ (\a+)\s*\ (\a+)$

It evalutes lines that look like this:
Code:

  [ 117] arnica             [  99] calamus            [  98] chervil

For some reason, the regex doesn't recognize that line as matching the pattern. No big deal, except it works fine for anyone else that attempts to evauate it. I have a vanilla, fresh installed copy of Zmud. Any ideas?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Wed Aug 22, 2007 2:35 am   
 
The regex doesn't match the line because... well... the regex doesn't match the line (unless the forum ate some of it - use the [code] tag).

You've got some escaped spaces in there which you don't need (spaces have no special function) and your only wildcards are \s, which matches spaces, and \a, which matches alarm characters. There's nothing matching the letters, numbers or square brackets. Try this instead:

^\s*\[\s*(\d+)\] (\w+)\s+\[\s*(\d+)\] (\w+)\s+\[\s*(\d+)\] (\w+)$

For future reference, here is a guide to regular expression syntax.

EDIT: I stand corrected on the function of \a - your pattern is matching the words, but still isn't matching the numbers or brackets. Feel free to replace the \ws in my pattern with \a.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)

Last edited by Fang Xianfu on Wed Aug 22, 2007 2:39 am; edited 4 times in total
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Aug 22, 2007 2:36 am   
 
I would use a pattern of
Code:
^\s+([\[\]\d\a ]+)\s+([\[\]\d\a ]+)\s+([\[\]\d\a ]+)$


It isn't exactly the prettiest, but will work. Perhaps if you told us what you want to do with the line we could suggest some other methods of doing it that would be faster and neater.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
rholcomb3
Newbie


Joined: 22 Aug 2007
Posts: 4

PostPosted: Wed Aug 22, 2007 5:18 am   
 
Okay, sorry about that. Let's try again. The perl regex button is checked in the trigger dialog box.

The regex is as follows (it's set as a trigger)

Code:
^  \ (\a+)\s*\ (\a+)\s*\ (\a+)$


It is used to capture the word and number from lines like this (there are several such lines that get outputted by the MUD at once, so here's a good sample)

Code:

  [ 117] arnica             [  99] calamus            [  98] chervil
  [ 113] coal               [ 100] coltsfoot          [   7] earwort
  [  93] faeleaf            [  97] galingale          [  99] horehound
  [ 119] kafe               [  92] kombu              [  25] leather
  [  96] marjoram           [ 100] merbloom           [   4] mercury
  [ 153] pennyroyal         [ 100] reishi             [  99] sparkleberry


It should then do the following with the data, line by line.

Code:
#addkey dRiftContents %2 %1
#addkey dRiftContents %4 %3
#addkey dRiftContents %6 %5


What the regex is supposed to accomplish is storing the name and number of herbs in my container (this is an IRE MUD). What's funny is it evaluates fine on many other person's copies of Zmud running the same version, just not mine. I'm using 7.21, as are the other folks whom it works for. This leads me to believe I must have set an option somewhere that makes it not work, but to eliminate that possibility I uninstalled Zmud, deleted the Zmud folder, and did a completely fresh install. Hopefully this explains better than my previous post.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Aug 22, 2007 5:40 am   
 
Ah I see. Lets just eliminate the whole problem of capturing with those nasty brackets. Also lets fix it so that the capture won't have trouble when there is only 1 item on the line. I find it a good idea to turn of the Use [] for Evaluation in the Preferences-Script Parsing section as well, but shouldn't be necessary. And now for a better script from my archives.
Code:
#CLASS {RiftCapture}
#VAR Rift {}
#VAR RiftTemp {} {}
#ONINPUT "RiftCap" {^ir$} {} "" {notrig}
#COND {^Glancing into the Rift, you see:$} {Rift="";RiftTemp=""} {case|notrig}
#COND {} {#IF (%match(%line,"%dh")) {#STATE RiftCap 4;#SET RiftCap 4 1} {RiftTemp=%concat(@RiftTemp,"|",%subchar(%insert("|",%insert("|",%line,56),28),"][","="))}} {looplines|param=30|prompt|notrig}
#COND {*} {#SHOW Failed to match prompt during rift capture, adjust param higher or correct other error} {notrig}
#COND {} {#DELITEM RiftTemp {};#FORALL @RiftTemp {#ADDKEY Rift {%trim(%word("%i",2,"="))} {%trim(%word("%i",1,"="))}}} {manual|notrig}
#ONINPUT "INR1" {^inr *$} {} "" {notrig}
#COND {^You store %d (*), bringing the total to (%d).$} {#ADDKEY Rift {%1} {%2};#STATE INR2 0} {case|notrig}
#ONINPUT {^outr *$} {} "" {notrig}
#COND {^You remove (%d) (*), bringing the total in the Rift to (%d).$} {#ADDKEY Rift {%2} {%3};#IF (%3<100) {#ECHO %2 low}} {case|notrig}
#ONINPUT "INR2" {^inr *$} {} "" {notrig}
#COND {^You store %d (*), bringing the total to (%d), which is the maximum for that type of object.$} {#ADDKEY Rift {%1} {%2};#STATE INR1 0}
#CLASS 0
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
rholcomb3
Newbie


Joined: 22 Aug 2007
Posts: 4

PostPosted: Wed Aug 22, 2007 5:41 am   
 
Fang and Vijilante (think I spelled that correctly) thank you very much both of you. Thanks to your suggestions and help, got it working like a charm.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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