MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: regex substitution



>that's what I was going to answer also, but the question was how could you
substitute using regexps: you can only use strsub() to substitute fixed strings.
>
>Let's take the example that was provided: replacing one or more consecutive
s's with the letter 't'. As you know, the regexp to match s's is "s+". But
since match() returns the index numbers of the matched string.. all you'd
have to do was use those numbers to change the actual string.

Oh yeah, there is another way to do this:
if (m=match(string,"%(.*%)s+%(.*%)"))
string=substitute("%1t%2",m);
endif

Since both methods only match the first occurrence of the string, you'd
probably have to put it in a while loop.




Home | Subject Index | Thread Index