Method Regexp.PCRE.Plain()->replace_positional()


Method replace_positional

string replace_positional(string subject, string subst)

Description

replaces matches in a string, with support for backreferences (matched groups)

Parameter subject

the string to be tested against the regular expression

Parameter subst

string to be inserted in place of each match. backreferences can be inserted into the string to be substituted using the syntax %[n]s where n is the nth matching string group, and 0 (zero) is the full match.

example:

> Regexp.PCRE.Plain("my name is ([a-zA-Z]+)")
      ->replace_positional("allow me to introduce myself: my name is john",
                          "%[0]s is my name");
  (1) Result: "allow me to introduce myself: john is my name"