subregex

Syntax: %subregex(s,regular-expression,NewS)
Related:
#REGEX, %regex, %match

test to see if string s matches the given Regular Expression. If it matches, the matched part of the string is replaced with the NewS string (which is also expanded for any variables or function calls). This continues until there are no more matches of the pattern in the string. The modified string is then returned. This is similar to the #SUB command but substitutes patterns within a string rather than patterns on the screen output. The %1..%99 variables can also be used in the NewS replacement string. Remeber that the pattern is a Regular Expression and not a zMUD trigger pattern.

Examples:

#SHOW %subregex("100 gold, 200 silver", "\d+", "%d")

displays:

%d gold, %d silver

#SHOW %subregex("100 gold, 200 silver", "(\d+)", "%eval(%1+10)")

displays:

110 gold, 210 silver

the quotes "" around the %eval function are needed to prevent %eval from being executed immediately when %subregex is parsed. With the quotes, it is executed each time a string is replaced, which is when %1 is defined.



Contents