Easy replacement when using text-icu regexes.
To install this, just use stack
.
The syntax used with OverloadedStrings
is meant to be similar to that used in other regular expression libraries in other programming languages.
Generally, input text is considered to be static.
>>> replaceAll "a" "b" "aaa"
"bbb"
>>> replaceAll "ab" "ba" "cdababcd"
"cdbabacd"
However, groups from the regular expression's matches can be insert using $1
(to insert the first group) or ${7}
(to insert the seventh group).
>>> replaceAll "(.*), (.*)" "$2 $1" "Beeblebrox, Zaphod"
"Zaphod Beeblebrox"
>>> replaceAll "4(\\d)" "${1}4" "7458"
"7548"
Dollar signs can be included in the output by doubling them ($$
).
>>> replaceAll "(\\d+\\.\\d+)" "$$$1" "9.99"
"$9.99"
Thank you!