echo all matches in line.

Post Reply
Newbe
Posts: 11
Joined: Fri Nov 27, 2009 10:29 am

echo all matches in line.

Post by Newbe »

Hello.
I've got trigger with pattern:

Code: Select all

\b(\w+)\b \b(\w+)\b sword
. I wanted to echo all matches in line, so i tried echo(matches[1]), but it echoes only first sword in the line. I thought it worked recursivly and would echo all swords. In debug log first sword is stored in

Code: Select all

capture group #0
and all others are kept in

Code: Select all

<regex mode: match all> capture groupe #0
. :'(

Hope you understood me and help me to solve the problem.

sephiel
Posts: 17
Joined: Mon Nov 30, 2009 10:35 am

Re: echo all matches in line.

Post by sephiel »

Not quite sure what you mean, but matches[1] is the whole line. So, if you have

^This is a thing I made up to test (\w+).$

then matches[1] is the whole line captured and matches[2] would be the wildcard in the brackets.

Hope that helps!

Newbe
Posts: 11
Joined: Fri Nov 27, 2009 10:29 am

Re: echo all matches in line.

Post by Newbe »

not really,
lets say a line like this comes:

Code: Select all

There is big sharp sword, red shiny sword and rusty broken sword.
then matches[1] would be "big sharp sword". I checked it in mud :P

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: echo all matches in line.

Post by Heiko »

No, matches[1] is the first *complete* match in the line. If you have 2 capture groups and chose the match all option and get a second match on the same line matches[] will look like this:
#1= first complete match
#2 = ---> first cap group of first match
#3 =---> second cap group of first match
#4 = second complete match
#5 = ---> first cap group of second match
#6 = ---> second cap group of second match

You can use display( matches ) to print the table matches to see what happens.

You can print all matches that you are interested in by iterating over the table matches.
This is being described in the manual.

Newbe
Posts: 11
Joined: Fri Nov 27, 2009 10:29 am

Re: echo all matches in line.

Post by Newbe »

Thanks for the info!
Now I can move on with my script :)

Post Reply