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
Jaerin
Apprentice


Joined: 10 Oct 2000
Posts: 132
Location: USA

PostPosted: Mon Jan 21, 2002 3:06 pm   

Help with pattern matching
 
Well I wondered if someone could help me out with some pattern matching. I have it working with Regex's but there appears to be a pretty major memory leak in the Regex system in the beta so I want to find a solution using normal pattern matching until the leak gets fixed.

The patterns I need to match are:


Single summon patterns:
--> Poisonous Toad:+
--> Ghast:A
Double summon patterns:
--> Poisonous Toad:B, Ghast:A
Triple summon patterns:
--> Poisonous Toad:B, Giant Spider:A, Ghast:A
4 summon patterns:
--> Poisonous Toad:B, Giant Spider:A, Ghast:A, Werewolf:B


Now initially I tried the following patterns to match it:

Single:
--> (*):(*)$
Double:
--> (*):(*), (*):(*)$
Triple:
--> (*):(*), (*):(*), (*):(*)$
4:
--> (*):(*), (*):(*), (*):(*), (*):(*)$

Major problem with these is the Double will match 3 summons because it will assign the % variables as follows:

%1:Poisonous Toad:B, Giant Spider
%2:A
%3:Ghast
%4:A

Now if there is a way that I can get something like %w to match 2 words that would work nicely.

Jaerin
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jan 21, 2002 3:25 pm   
 
First, I suggest using ? to match what comes after the colon since from your example it seems that this will always be just one character.

Second. try using this in the triggers:
#IF (!%pos(",", %1)) {commands for trigger}

What this does is to check if what is captured in %1 does not have a comma. If it does have one, then what we captured doesn't belong to that trigger. If it doesn't have one, then that trigger is correct for what was captured and we proceed to do the commands of the trigger.

Kjata
Reply with quote
Jaerin
Apprentice


Joined: 10 Oct 2000
Posts: 132
Location: USA

PostPosted: Mon Jan 21, 2002 3:33 pm   
 
Well it seems that Zmud has had a bit of Regex code in it all along. I was able to put something together. This isn't going to look completely right because I know the forum doesn't like (plus) symbols for some reason but here it goes:


--> ([A-Z a-z 0-9 ~- %s]):([A-E ~~ ]), ([A-Z a-z 0-9 ~- %s]):([A-E ~~ ]), ([A-Z a-z 0-9 ~- %s]):([A-E ~~ ]), ([A-Z a-z 0-9 ~- %s]):([A-E ~~ +])$


Well you get the gist of it anyways. I tested it out and it works great. Probably even more efficiently than the way I was doing it before.

There actually is a possibility of two characters after the :. Either A-Z or(plus) or ~ and then A-Z or (plus)

Thanks for the help anyways

Jaerin
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