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
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 1:14 am   

Pattern match function?
 
Is there a pattern match function? Say, given some specified text (NOT from the mud or from the command line) can I perform a patter match for substitutions or for finding an index of the first part of the matched string?

For example, given the text:

An open beaded hemp bag and a closed worn wool sack.

I want to find and remove 'beaded hemp ' and 'worn wool ' from the text. I'd make a regular expression that basically looked like:

{a|an} {open|closed} (*){sack|pouch}

and then delete the part in parentheses. I can't see any way to use the pattern matching except in triggers though. Thoughts?

FWIW: I'm trying to modify the 'clook' trigger someone posted before. Maybe I can put a #SUB in the beginning and filter out the intervening part before it gets into the other trigger. However, the general question still intrigues me.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jul 13, 2002 2:29 am   
 
If it's not going to come from the Mud (use a trigger) and it's not going to come from the command line (use an alias), where is it going to come from? Being vague about what you are attempting to do just makes it more difficult to answer.

LightBulb
Senior Member
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 3:36 am   
 
Well, I didn't want to get specific for a reason but I'll go ahead and post the -exact- problem I wish to solve:

Given a text string from the MUD that can contain a number of different things I want to collapse down different containers into a single type:

In the open backpack you see a rock, a knife, an open green pouch, an open blue pouch, an open dusty pouch, a bumblebee and a knife.

I want to generate the output:

1x a rock
2x a knife
3x an open pouch
1x a bumblebee

Right now, I have a trigger set that correctly produces a list that looks like this:

1x a rock
2x a knife
1x an open green pouch
1x an open blue pouch
1x an open dusty pouch
1x a bumblebee

So, the bottom line is, before the script finishes parsing the input I want to filter out the text between open and pouch.
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 3:40 am   
 
Just as an FYI, I did create a #SUB trigger that correctly removes the parts I want -but- it does it -after- the other trigger so the output is:

1x a rock
2x a knife
1x an open pouch
1x an open pouch
1x an open pouch
1x a bumblebee

Which is not any better at all. If I could make the #SUB trigger go before the other trigger that might work, but I'm not at all certain how to set trigger order and if it'll matter at all with #SUB.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jul 13, 2002 5:21 am   
 
quote:

Is there a pattern match function? Say, given some specified text (NOT from the mud or from the command line) can I perform a patter match for substitutions or for finding an index of the first part of the matched string?

For example, given the text:

An open beaded hemp bag and a closed worn wool sack.

I want to find and remove 'beaded hemp ' and 'worn wool ' from the text. I'd make a regular expression that basically looked like:

{a|an} {open|closed} (*){sack|pouch}

and then delete the part in parentheses. I can't see any way to use the pattern matching except in triggers though. Thoughts?

FWIW: I'm trying to modify the 'clook' trigger someone posted before. Maybe I can put a #SUB in the beginning and filter out the intervening part before it gets into the other trigger. However, the general question still intrigues me.



Have you checked out the pattern-matching operator (~=)? combined with perhaps a %remove() function, it should provide you with what you're asking for.

li'l shmoe of Dragon's Gate MUD
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 3:05 pm   
 
Any hints on finding this in the help file? I love zMud but the help file is a bit lacking.
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 3:14 pm   
 
Ok, found an obscure reference to =~ (not ~=). I was able to make a few tests to determine how it works -- it's exactly what I wanted. A perfect answer to my first question. :)

=~ Usage:

#IF ("test" =~ "*es(*)") {#ECHO Yes: %1} {#ECHO no}

Echoes: Yes: t
Reply with quote
Thandril
Adept


Joined: 03 Dec 2000
Posts: 260

PostPosted: Sat Jul 13, 2002 5:26 pm   
 
Unfortunately the example I gave works fine from the command line, but within a trigger or an alias it won't work because it doesn't replace %1...%n. I'm getting the match but I can't access the match string. At least I can use the pattern to do a quick comparison. Oh well.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jul 13, 2002 6:13 pm   
 
This would be much easier if we had your existing trigger to work from so we wouldn't have to reinvent your counting routine (which already works). Anyway, here's a routine to take the second word from each item (the first is either "a" or "an") and the last word (if it's not the second).

#TR {In the * you see (*).} {#FORALL %replace(%1,",","|") {#IF (%numwords(%trim(%i)) > 2) {#SAY {%word(%trim(%i),2) %word(%i,%numwords(%i))}} {#SAY {%word(%trim(%i),2)}}}}

You might need to use %* in place of * to get the commas.

LightBulb
Senior Member
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