regex-applicative icon indicating copy to clipboard operation
regex-applicative copied to clipboard

How to replace a suffix?

Open bapcyk opened this issue 2 years ago • 3 comments

Hello dear author, this package is brilliant.

It's not a bug, just a question: is it possible (and how?) to replace a suffix (or prefix) in a string? Because the replace replaces a fragment everywhere, for instance in the middle of a string. For example, I want to replace ".exe" - it's suffix/executable extension. All my attempts replace it in "aaa.exe.tail" too. I tried to use empty but it does not help.

replace (some anySym <* ".exe") "aaa.exe"  -- the simplest example

bapcyk avatar Mar 30 '23 13:03 bapcyk

Maybe there is a way to implement missing $ and ^ typical for many regex syntax?

bapcyk avatar Apr 04 '23 15:04 bapcyk

For prefixes, you should look at findFirstPrefix, findLongestPrefix, and findShortestPrefix. For suffixes, I think you need to use match with an appropriate argument.

treeowl avatar Apr 04 '23 17:04 treeowl

For prefixes, you should look at findFirstPrefix, findLongestPrefix, and findShortestPrefix. For suffixes, I think you need to use match with an appropriate argument.

I mean for replace, not for matching/searching. Otherwise the replace function replace it many times in any position where it finds the pattern

bapcyk avatar Apr 05 '23 11:04 bapcyk