Replace first

From Kolmafia
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Function Syntax

string replace_first(matcher pattern ,string replacement )

  • pattern is the regular expression to use
  • replacement is used to replace a match of the pattern

This function first resets the matcher pattern. It then scans the input sequence looking a match of the pattern. Characters that are not part of any match are appended directly to the result string with the first match replaced by the replacement string.

Simple Example

For example:

string input = "zzzdogzzzdogzzz";
matcher test_match = create_matcher("dog", input);
string result = replace_first(test_match, "cat");
print(result);

Will result in the following being printed:

zzzcatzzzdogzzz


See Also

replace_all()