Regexp problem..

Posted by Shadowfyr on Mon 25 Nov 2002 01:00 AM — 5 posts, 13,135 views.

USA #0
I have a set of triggers like:

^(\d\d:\d\d\s)?(\[hero\])(.*)
^(\d\d:\d\d\s)?(\[newbie\])(.*)
^(\d\d:\d\d\s)?(\[sales\])(.*)
^()(\[(gossip|bs|aod|events|druid|healer|bardic)\])(.*)

Which are intended to support setting a trigger that colors the indented lines that follow the initial channel. I use th following to reset the color so further indents don't do anything.

^()(\S{1,})(.*)

While it just occured to me while typing this that making it:

^(\d\d:\d\d\s)?(\S{1,})(.*)

would solve my immediate problem, I would prefer to not have to test for the channel name in the script. i.e. the current form is this:

1. Line triggers with [hero] - color set to color for the [hero] trigger.
2. ()(\S{1,})(.*) also matches in the next trigger, so check if it starts with [hero].
3. If it does, don't reset the color to 'no change', since we would be undoing what we just set.
4. Also match on key words like certain player names, etc. and color them seperately in other triggers.

I would like instead to use the (?<!stuff_to_ignore) feature of the regular expressions to eliminate the whole set of tests needed to make sure I don't turn off my trigger the same time I activate it. The script should 'only':

1. match on channel traffic.
2. get the color from the trigger that called it and set the one to color indented text to match.

So no special tests are needed, but I can't do it this way and also have 'keep evaluating' set to allow other triggers to take effect on the same line.

However after several attempts, including this one:

^(?<!\d\d:\d\d\s)(?<!\[)(?<!gossip|bs|aod|events|druid|healer|bardic)(?<!\])(.*)

all my attempts matched on 'any' line, instead of excluding the ones with the things I want to not-match in them. According to the regular expression docs, this should be possible, but I can't get it to work right. :p
USA #1
Hmm. Ran into another one.. This was intended to trap lines like:

Player Name 1 1 2 10 13

But the following failed to work:

^(\w)( \w)?\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+

adding .* to the end seemed to math all lines from some reason while the following attempts showed this:

^(\w)( \w)? - Worked.
^(\w)( \w)?\s+ - Worked.
^(\w)( \w)?\s+\d+ - Failed (hmm...)
^(\w)( \w)?\s+\d{1,} - Failed.
^(\w)( \w)?\s{1,)\d{1,} - Failed.
^(\w)( \w)?.*\d+.*\d+.*\d+.*\d+.*\d+ - Failed (this is getting annoying...)
^\s*(.*)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+ - Works??? What the?

I think something strange is going on in you regular expression processing, since all the ones that failed 'should' have been valid as far as I can tell. It may also explain why I can't get the other one I tried to do to work right. :p
Australia Forum Administrator #2
Quote:

But the following failed to work:

^(\w)( \w)?\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+


Your expression is flawed, sorry. :)

The part (\w) will match a single word character. The spec does not say that \w matches any number of word characters. Thus you need to add a "+" to the end of it, like this, which works ...


^(\w+)( \w+)?\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+
Australia Forum Administrator #3
Quote:

1. Line triggers with [hero] - color set to color for the [hero] trigger.
2. ()(\S{1,})(.*) also matches in the next trigger, so check if it starts with [hero].


Can't you solve this by sequencing the triggers so that (2) is done first? That is, you turn off colouring whenever you get a line with no leading space, and then, in the next trigger, you test if the same line is supposed to re-colour it?
USA #4
> ^(\w+)( \w+)?\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+

Oops..

>Can't you solve this by sequencing the triggers so that (2) is done first?
>That is, you turn off colouring whenever you get a line with no leading space,
>and then, in the next trigger, you test if the same line is supposed to re-colour it?

There was some reason I didn't do it in that order, but I can't remember why at the moment.. :p Oh well..