Reg Exp Trigger only matching once on a line?

Posted by Flannel on Mon 07 Apr 2003 02:23 AM — 5 posts, 14,636 views.

USA #0
Ive got a series of lines that look like this:
charm person        72%  create food         81%  create water        72%  
theyve got the name of the skill, then some space, then the percentage of the skill, My regExp only seems to match on the first one of the line (There are 9 lines, it only counts up 9 matches each time the list is encountered)

My Reg Exp Looks like this:
([a-z ]{2,})[ ]+(\d{1,3})\%
the trigger is setup to ignore case, Regexp, Keep Evaluating, and repeat on the same line.
It also colors the line (the whole line), but is set to match any on any, so I dont think that would stop it.

Now, for a while, a workabout I had was to simply put three of the above Regexps's in a trigger, with a
 [ ]+ 
in between, but there arent always three on a line, so that makes my script messy, and three times as long (trigger/script for one, two, and three on a line) for this portion.

What also puzzles me is the fact that it colors the whole line, instead of just what the Regexp matches on.

Im using 3.34, so it has nothing to do with the new changes in 3.35
Amended on Mon 07 Apr 2003 02:29 AM by Flannel
Australia Forum Administrator #1
If you turn off "repeat on same line" it only colours one group.

The way triggers work, it may match three times, but it only calls the script once. A fairly simple way around would be to have the trigger match text three times, but make the last two optional, something like this:


([a-z ]{2,})[ ]+(\d{1,3})\%[ ]?(?:([a-z ]{2,})[ ]+(\d{1,3})\%)?[ ]?(?:([a-z ]{2,})[ ]+(\d{1,3})\%)?


Then in your script you would test for wildcards 1-3, 4-6, and 7-9
Amended on Mon 07 Apr 2003 03:35 AM by Nick Gammon
USA #2
Alright, that works, except for the fact that between the different ones, there is two spaces, so the trigger picks up the second space, as part of the name of the skill.

To my knowledge, one cannot do a [ ] (with two spaces), and [ ]{2}? wont work correctly, to my knowledge (as it currently isnt), would it help any to have the extra spaces inside the lookahead?

Oh yeah, as another bit of info, there is two extra spaces at the end of the line, (the code from the mud, does skill x-(skill name length) spaces skill percent then two spaces, three times.

So I assume that the [ ]{2}? is taking up the end spaces (for the less-than three lines) and then the spaces wont catch... So, if I were to put them in the look-ahead, what would that look like? and, more importantly, would that be the best way to do it? (Im still a bit fuzzy about lookahead matches)
Australia Forum Administrator #3
Well, you could always left-justify it to get rid of the space.

However this ought to work - the skill always starts with a-z, and *then* might have a space, so how about this to match:

[a-z][a-z ]+

The first set doesn't have a space, the second does. Since you must have both sets this immediately implies 2 or more characters.
USA #4
alright, that makes sense, but then wouldnt the two spaces before that not match? (because there's only one in the Regexp)

(Edited:)
I got it anyway though. Just put the two spaces in the lookahead, and then that takes care of the leading space.

Thanks for all your help Nick.