the
trReplace
of
(
haystack ,
needle ,
noodle )
the
trReplace
of
(
haystack ,
options ,
needle )
the
trReplace
of
(
haystack ,
options ,
needle ,
noodle )
trReplace
(
haystack ,
needle ,
noodle )
trReplace
(
haystack ,
options ,
needle )
trReplace
(
haystack ,
options ,
needle ,
noodle )
Haystack yields any string
. Options yields a string
starting with a hyphen. Needle and noodle yields string
s describing sets of characters.
In its basic form, the trReplace
function returns the string haystack with the first occurrence of any of the characters in needle replaced with the corresponding character in noodle.
If options contains s
but not d
, then noodle is optional. If noodle is specified, the first occurrence of any of the characters in needle is replaced with the corresponding character in noodle, then any consecutive occurrences of that character are removed. If noodle is not specified, the first run of consecutive occurrences of any one character in needle are replaced with a single occurrence.
If options contains d
but not s
, only needle must be specified. The first occurrence of any character in needle is removed from haystack.
If options contains both d
and s
, both needle and noodle must be specified. The first occurrence of any character in needle is removed from haystack. The first run of consecutive occurrences of any one character in noodle are replaced with a single occurrence.
If options contains the character c
, the complement of needle is taken, so that characters not in needle will be matched instead.
Needle and noodle describe sets of characters, not strings. A range of characters can be specified by putting a hyphen between two characters; to match a literal hyphen, put a hyphen at the beginning or end. For example, the following pattern matches all numbers and basic Latin letters, as well as hyphens: A-Za-z0-9-