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
Radamanthas
Newbie


Joined: 22 Nov 2004
Posts: 9

PostPosted: Wed May 14, 2008 12:42 pm   

Pattern Matching Woes
 
Hello all -

Trying make a trigger that will capture certain elements of some mud output. Here is a sample of that output:

Frontier - Boone: Boondock(T) Carson(I) Fremont(B)
Garr - Garioso: Ashten(R)
Gephoria - Gwarrior: Gforce(A)
Gliese - Deklax: Crash(I) Valis(A)
Gough - Dunavant: Gough Prime(R) New Gough(T)
Granite - Freya: Pebble(T)
Happy - Priscilla: Smile(R)
Havefun - Bourbon: Bourbonballs(A) Whiskey Map(T)

The elements I want to capture, are the name that appear after the colon, in each line. Here is the pattern I started with:

(%w) - (%w)~: (%w)~({A|R|T|I|B|L|N}~)

In this example, I want to be able to add %3 to a string list (note that the letter in the parens will always be one of the seven in the trigger - and I do NOT want that part for the string list). So in the output above, in the case of the 'Garr' line, I want to just get 'Ashten', for the list.

I know I might have to make three seperate triggers to account for the fact that each line of output might have 1-3 elements I need to get in it (as in the 'Frontier' line, above).

Here's where I run into trouble...some lines will have two word names, instead of one (as in the 'Gough' line above). I don't know how to catch the whole name (which I need), without using (%*)...however, if I use (%*) the trigger barfs on other lines, because it grabs 2 or even 3 elements where I only wanted one.

Basically, given the example above, I would want to nab:
Boondock|Carson|Fremont|Ashten|Gforce|Crash|Valis|Gough Prime|New Gough|Pebble|Smile|Bourbonballs|Whiskey Map

Can anyone give me some insight? TIA
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 14, 2008 1:14 pm   
 
This is all untested:

Code:
#REGEX {^(\a+) - (\a+)\: (\a+(?: \a+)?)\([ARTIBLN]\)( (\a+(?: \a+)?)\([ARTIBLN]\))?( (\a+(?: \a+)?)\([ARTIBLN]\))?} {whatever you want to do in the triger here.}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Wed May 14, 2008 5:28 pm   
 
This pattern has perhaps two too many captures. You may find that

Code:
^(\a+) - (\a+)\: (\a+(?: \a+)?)\([ARTIBLN]\)(?: (\a+(?: \a+)?)\([ARTIBLN]\))?(?: (\a+(?: \a+)?)\([ARTIBLN]\))?


works a little better, because it eliminates the extraneous captures. I do wonder if this pattern is perhaps too restrictive, because it works only for up to three items, and only for up to two words per item. If you can ever have more than two words per item or three items per line, you're going to need a different pattern. Perhaps something with [^\(] would work well in that case.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 14, 2008 6:05 pm   
 
If words per items vary the gambit [^\(] might be a good way to go.
If however the number of items can go beyond 3 I think manually extending the pattern with additional (?: (\a+(?: \a+)?)\([ARTIBLN]\))?
Is probably the right move and then just test for %1,%2,...,%n
if instead you do something like (?: (\a+(?: \a+)?)\([ARTIBLN]\))*
then you'll need to use something like %regex or %subregex to break the string down once more into its component parts.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Radamanthas
Newbie


Joined: 22 Nov 2004
Posts: 9

PostPosted: Fri May 16, 2008 1:04 pm   
 
Thanks for the help guys! I haven't used regex scripting before..now I see I might have to start learning it, as it is obviously more flexible...

Still running into a snag, however...The script works perfectly, in that it will capture all the elements that I want, in a line-by-line basis (tested all possible combinations, and they work). However, in setting up the trigger, I am having it add the captured elements to a string list, with this:

(Note: the elements I want in the list will be %3, %4, and %5 - using #additem, instead of %additem to avoid creating duplicates, in the string list)

#additem all_planets %3
#if (%4) {#additem all_planets %4}
#if (%5) {#additem all_planets %5}

The problem is - now - that when I run the script, it seems to be adding corrupted data to the string list - for example, using the sample output from my first post, instead of adding "Whiskey Map" to the string list....it might just add "Whiskey"..or "Map"...or even just a blank line!

Since, in testing, everything works fine, I am suspecting that the problem lies in the fact that there is too much data coming from the mud all at once, for zmud to handle efficiently. When I issue the command to get the output that I need, to operate this script on, the mud dumps out 145 lines of output, all at once - and I am asking zmud to process each line individually...

As it happens, I own a copy of cmud. After figuring out how to add the trigger in cmud, I tested it on the same thing, and everything works perfectly, and the proper string list is generated, which further inclines me to believe that zmud's problem is too much data, too fast. (And before you suggest it, I would really prefer to stay with zmud - I know cmud is supposed to be bigger, better, faster, etc...but it is just too confusing for me - too much of an old dog, I guess)

So - does anyone have any suggestions as to how I can get zmud to process all the data more quickly and efficiently, so I can test my theory?

Sorry for the long-ish post, and TIA
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