Reputation: 579
I use Text.Regex package right now.
I try to use subRegex for word boundary,
let r = mkRegex "\\bdog\\b"
subRegex r "mydog dog" "(\\0)"
output => "mydog dog"
I also try following:
let r = mkRegex "\\b(dog)\\b"
subRegex r "mydog dog" "(\\0)"
output => "mydog dog"
I try to change "mydog dog" => "mydog (dog)"
Upvotes: 1
Views: 78
Reputation: 89093
Text.Regex
from the regex-compat
package uses POSIX-compatible regular expressions, not PCRE ones.
In POSIX regular expressions, the left word boundary is \<
and the right word boundary is \>
:
ghci> let r = mkRegex "\\<dog\\>"
ghci> subRegex r "mydog dog" "(\\0)"
"mydog (dog)"
Upvotes: 1