slightly advanced Regex trigger - help wanted

Posted by Conrad on Tue 18 Apr 2006 12:21 AM — 2 posts, 10,486 views.

#0
Greetings all.

I'm looking to set up an advanced trigger as part of a plugin I've been developing. The trigger I'm trying to set up fires on each of the targettable mobs in a given room description.

The targetable mob descriptions can have a variety of forms (where Mob123 may be multiple words):

Mob123 is standing around ( facing north )
A Mob123 is standing here ( facing north )
The Mob123 snarls as you enter ( facing north )
An Mob123 cowers under your gaze ( facing north )

and so on. I'm able to trigger on the lines using "\( facing (\w+) \)"

What I want to do is this ...

1. Have the trigger return a %x variable with anything before the word "is" in the description.
2. If the first word of the variable is "A, An, or The", strip this from the result
3. If the line does not contain the word 'is', return the first word of the line unless it is 'A, An, or The', in which case return the next word.

I've been banging my head on this for about 6 hours, mostly because I'm not familiar with Lua syntax ...

Anyone bored enough to lend a hand?


Australia Forum Administrator #1
First I would suggest using the PCRE regexps, not the Lua ones, as that is what triggers use anyway.

To have an optional "A", "An" or "The" start the trigger with:


^(?:A |An |The ){0,1}


This makes a subpattern, of A, An or The, and makes it non-capturing. The {0,1} makes it zero or one occurrence.