|
anylo Beginner
Joined: 21 Feb 2001 Posts: 28 Location: Finland
|
Posted: 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' |
|
|
|
Daneel Newbie
Joined: 26 Aug 2004 Posts: 4 Location: Klagenfurt
|
Posted: 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" ?
|
|
|
|
anylo Beginner
Joined: 21 Feb 2001 Posts: 28 Location: Finland
|
Posted: Thu Aug 26, 2004 7:45 am |
Well, the following commands are:
#var target %1
use @attack_skill at @target |
|
|
|
Daneel Newbie
Joined: 26 Aug 2004 Posts: 4 Location: Klagenfurt
|
Posted: 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. |
|
|
|
geniusclown Magician
Joined: 23 Apr 2003 Posts: 358 Location: USA
|
Posted: 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 |
|
|
|
anylo Beginner
Joined: 21 Feb 2001 Posts: 28 Location: Finland
|
Posted: 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'. |
|
|
|
Serentus Apprentice
Joined: 28 Sep 2001 Posts: 103 Location: USA
|
Posted: Fri Aug 27, 2004 10:43 am |
#VAR target {%1}
|
|
_________________ -Serentus- |
|
|
|
anylo Beginner
Joined: 21 Feb 2001 Posts: 28 Location: Finland
|
Posted: Fri Aug 27, 2004 11:18 am |
Darn, way too easy solution.
|
|
|
|
|
|