Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Reg Exp Trigger only matching once on a line?

Reg Exp Trigger only matching once on a line?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Flannel   USA  (1,230 posts)  Bio
Date Mon 07 Apr 2003 02:23 AM (UTC)

Amended on Mon 07 Apr 2003 02:29 AM (UTC) by Flannel

Message
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

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 07 Apr 2003 03:34 AM (UTC)

Amended on Mon 07 Apr 2003 03:35 AM (UTC) by Nick Gammon

Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #2 on Mon 07 Apr 2003 04:24 AM (UTC)
Message
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)

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 07 Apr 2003 04:38 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Mon 07 Apr 2003 04:43 AM (UTC)

Amended on Mon 07 Apr 2003 04:54 AM (UTC) by Flannel

Message
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.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


13,836 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.