|
manbat Novice
Joined: 21 Mar 2009 Posts: 35
|
Posted: Mon Oct 19, 2009 12:43 am
Regex pattern not matching |
Code: |
<trigger name="AGhunt" priority="3300" regex="true" id="298">
<pattern>{the|a}\w? \w*?\s?@AGhunttarget\s?\w*?, {right here|nearby to the}\s?(\w+?)\.$</pattern>
<value>#T+ AGhuntbad
#T+ AGcombatless
#T+ AGcombatadd
#T+ AGmain
#T- AGwalkchecklook
#IF (!%1) { kill @{AGkillsteal}.@AGhunttarget }
{ c 'holy flame' %1 @{AGkillsteal}.@AGhunttarget }
#T- AGhunt</value>
</trigger> |
My pattern should be something like
Code: |
a small minotaur, right here. |
or
Code: |
a minotaur slave, nearby to the west. |
However for some reason I can't figure this out....
{the|a} - match either "the" or "a"
\w? - allow to match "them" or "an"
\w*? - allow to match anything that starts with a word character, and keep going until it hits a space or digit character
\s? - allow to match a space
@AGhunttarget - a variable
{right here|nearby to the} - match either "right here" or "nearby to the"
\s? - allow to match a space
(\w+?) - allow to match a word like "west" and then put it into %1
\.$ - match a period and then end of line
Do I have that right? |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Mon Oct 19, 2009 12:55 am |
(?:them?|an?) (?:\w+ )?@AGhunttarget(?: \w+)?, (?:right here|nearby to the \w+)\.
(?:
them? to match 'the' or 'them'.
or
an? to match 'a' or 'an'.
)
(?:\w+ )? to match a word with a space after it or nothing at all.
@AGhunttarget for your target.
(?: \w+)? to match a space with a word after it or nothing at all.
(?:
right here
or
nearby to the \w+
)
\. period. |
|
|
|
manbat Novice
Joined: 21 Mar 2009 Posts: 35
|
Posted: Mon Oct 19, 2009 1:07 am |
Interesting.. where is "(?:" documented? I assume putting a ? following a character makes that character optional?
|
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Mon Oct 19, 2009 1:12 am |
manbat wrote: |
Interesting.. where is "(?:" documented? I assume putting a ? following a character makes that character optional? |
In the documentation for #regex. (?:) is the same as () except it doesn't store the expression in the %1-99 variables. As for ?, from the help file: ? matches zero or one of the previous pattern. In example:
an? will match a or an.
(?:an)? will match an or nothing. |
|
|
|
manbat Novice
Joined: 21 Mar 2009 Posts: 35
|
Posted: Mon Oct 19, 2009 1:16 am |
Ahhh... I get it now.... Thanks! I saw that there but didn't understand how it would be applied.
|
|
|
|
|
|