Skip to content

erochest/text-regex-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

text-regex-replace

Travis CI status

Easy replacement when using text-icu regexes.

Installation

To install this, just use stack.

Usage

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"

Contributors!

Thank you!