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
anylo
Beginner


Joined: 21 Feb 2001
Posts: 28
Location: Finland

PostPosted: Thu Aug 26, 2004 7:34 am   

Regex for different amount of parameters
 
Is there any way to capture following lines with one regex?

Friend says 'target ogre'
Friend says 'target ogre 1'
Friend says 'target ogre mage'
Reply with quote
Daneel
Newbie


Joined: 26 Aug 2004
Posts: 4
Location: Klagenfurt

PostPosted: Thu Aug 26, 2004 7:43 am   
 
Hmm, why don't you simply check for just the common part of these messages, i.e. "Friend says 'target ogre" ?
_________________
--
Check out my gallery:
http://www.unfolded.com/gallery/
Reply with quote
anylo
Beginner


Joined: 21 Feb 2001
Posts: 28
Location: Finland

PostPosted: Thu Aug 26, 2004 7:45 am   
 
Well, the following commands are:

#var target %1
use @attack_skill at @target
Reply with quote
Daneel
Newbie


Joined: 26 Aug 2004
Posts: 4
Location: Klagenfurt

PostPosted: Thu Aug 26, 2004 7:51 am   
 
That explains it. You should be able to do it with a perl regular expression though, check out: http://www.troubleshooters.com/codecorn/littperl/perlreg.htm

Something like:
^/.target $1'

This is just out of my head and I can't check it because I'm at work ... please don't blame me if it does not work. $1 is supposed to be your variable.
_________________
--
Check out my gallery:
http://www.unfolded.com/gallery/
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Fri Aug 27, 2004 12:55 am   
 
Do you want %1 to be whatever you're targetting, such as "ogre mage"? If so, then you can do it with a single parameter:
Quote:
#REGEX {^Friend says 'target (.*)'} {use @attack_skill at %1}


If you want to seperate out the words to be different parameters, you can do:
Quote:
#REGEX {^Friend says 'target (\w+)\s?(\w*)\s?(\w*)'} {use @attack_skill at %1 with %2;defend %3}

If you need more than 3 parameters, tack on an extra "\s?(\w*)" for each potential parameter.

In short, the first \w has a + because you'll always have several letter (word) characters... each \s? is white space that may or may not be there, and each \w* is multiple letter characters that may or may not be there, with () to capture into parameters.
_________________
.geniusclown
Reply with quote
anylo
Beginner


Joined: 21 Feb 2001
Posts: 28
Location: Finland

PostPosted: Fri Aug 27, 2004 6:51 am   
 
geniusclown wrote:
Do you want %1 to be whatever you're targetting, such as "ogre mage"? If so, then you can do it with a single parameter:
#REGEX {^Friend says 'target (.*)'} {use @attack_skill at %1}


Thanks mate, that works just fine. But.

zMUD seems to be bugging. When I store the parameter %1 which is for example 'ogre 1' it loses the '1' part of the parameter.

Code:

#REGEX {^Friend says 'target (.*)'} {#ECHO target is %1;#VAR target %1;ECHO target is now @target}


With line 'Friend says 'target ogre 1' gives echoes first 'target is ogre 1' and then 'target is ogre'.
Reply with quote
Serentus
Apprentice


Joined: 28 Sep 2001
Posts: 103
Location: USA

PostPosted: Fri Aug 27, 2004 10:43 am   
 
#VAR target {%1}
_________________
-Serentus-
Reply with quote
anylo
Beginner


Joined: 21 Feb 2001
Posts: 28
Location: Finland

PostPosted: Fri Aug 27, 2004 11:18 am   
 
Darn, way too easy solution.
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