Why regex libraries don't have replace function

Hi,

I am looking at wiki page about regex libraries in Haskell and cannot find any explanation why replace feature is missing.

regex-compat is an exception, but it is kind of deprecated library.

5 Likes

text-regex-replace: Easy replacement when using text-icu regexes. ?

5 Likes

regex-rure doesn’t have replacement (the underlying C library doesn’t have it) but you could implement it.

1 Like

Regular expressions aren’t/weren’t always valued fully in the Haskell world.

Hledger.Utils.Regex has a simple replace.

regex: Toolkit for regex-base is a modern regex lib including replace.

1 Like

The semantics of replacing seems rather hairy to me. Which match should we replace? Should we replace multiple matches? What if they are overlapping?

2 Likes

Here’s an easy way to do search-and-replace in Haskell. Try the streamEdit function in replace-megaparsec: Find, replace, and split string patterns with Megaparsec parsers (instead of regex)

2 Likes

regex looks promising! @chris fyi many of the links on regex.uk are broken! The first link I clicked was examples.regex.uk, but I can’t resolve that name.

2 Likes

Sorry for the breakage. A change of host means those links aren’t easy to restore — I will replace them with working ones on the next release.

3 Likes