|
Rolly Wanderer
Joined: 16 Oct 2006 Posts: 62
|
Posted: Thu Nov 23, 2006 2:28 pm
Help capturing REGEX |
Hi I am fairly new to this but I have a lot of trigger scripts from ACP like
{\w+ forms a spear hand and stabs out at you\.$}
to trigger {#set acp_attacked}
Can I use this to capture the name of the attacker into a variable or do I need a sepparate trigger like
{%w forms a spear hand...}
I am leary of having 2 triggers for the same line because it might not trigger both times or could slow things way down. Is there a safe way to get this to work without ruining the orriginal purpose of the trigger?
All I want it to do is to put the attacker's name into a variable that will show up on a button and when pressed the button would target the attacker for retaliation. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Nov 23, 2006 2:39 pm |
It's pretty simple actually - just put brackets round the wildcard and refer to it using %nn like you would any other wildcard. So:
#regex {(\w+) forms a spear hand and stabs out at you\.$} {#set acp_attacked;#va Attacker %1} |
|
|
|
Rolly Wanderer
Joined: 16 Oct 2006 Posts: 62
|
Posted: Sat Nov 25, 2006 2:47 am Help capturing REGEX |
Thanks a bunch it works well for many cases. One more question. On a more complex trigger like:
(?:\w+ slashes into|Lightning\-quick\, \w+ jabs|With a steady hand\, \w+ batters) your (left arm|right arm|left leg|right leg|head|torso) with .+?\.$
Where the command line is this:
#set acp_attacked
#set acp_venomed
acp_bodyhit %1
I assume you would do something like:
(?:(\w+) slashes into|Lightning\-quick\, (\w+) jabs|With a steady hand\, (\w+) batters) your (left arm|right arm|left leg|right leg|head|torso) with .+?\.$
#set acp_attacked
#set acp_venomed
#var Attacker %1
acp_bodyhit %2
Is that correct? or does each (\w+) need its own #var? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Nov 25, 2006 5:42 am |
As they all appear before any of the variable text that follows, you can probably more easily remove \w+ from the list itself and place it in its own () in front of the list. This will put the stuff you want to work with in %1 while leaving the extraneous stuff for whatever else you want to do with it.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Nov 25, 2006 6:57 am |
To show more simply what Matt means:
(\w+) (?:slashes into|Lightning\-quick\, jabs|With a steady hand\, batters) your (left arm|right arm|left leg|right leg|head|torso) with .+?\.$
Which makes it a bit simpler. Your syntax is right in this case. |
|
|
|
|
|