I have a function remove
which takes a regex as a string and another string. It removes anything that matches the regex from the second string and returns it.
At the moment, I'm calling the remove
function with literal regex strings, for example:
remove "(my|a)?string" "Test string" -- returns "Test "
This program is going to grow and there will be lots of regex's to call, and each one may be used several times throughout the program. Should I be storing them like this:
myregex = "(my|a)?string"
or should I be making a data type or something else?
Thanks
One option would be to use partial application as in:
remove regex str = <generic code to remove the regex expression from string>
For each specific type of regex you want to apply, you can write a function like:
removeName = remove "<name_regex>"
and so on. Then you can use those functions like
removeName "myname"
If performance is a concern, any regexen you intend to use multiple times should be compiled once and stored in compiled form. See also the documentation for makeRegex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With