Some problem with replace()

Post Reply
azure_glass
Posts: 97
Joined: Wed Jul 25, 2012 12:35 pm

Some problem with replace()

Post by azure_glass »

Hi!

I have some problem with replace()

pattern(perl regex): (1,2,3,4)

code
selectString(matches[2], 1)
replace(matches[2].." [GL]")

Text from mud:

5, 6, 1, 8, 2

is

5, 6, 1 [GL], 8, 2

should be:

5, 6, 1 [GL], 8, 2 [GL]


What I'm doing wrong?
English is not my native language. If you don't understand what im writing ask. :)
Ubuntu 17.04, Mudlet 3.1

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Some problem with replace()

Post by Jor'Mox »

In general, triggers fire once per line. So that is looking for a single instance of 1, 2, 3, or 4. It found one, did what it was supposed to do, and then was never looked at again. You need to check "match all"... and then I believe it will be returned as a series of matches... so matches[1] and [2] will be for your first match, then [3] and [4] are for the second, and so on.

Post Reply