I have a string like:
str = 'in europe it costs 250 eur'
or:
str = 'in europe it costs a lot (250eu)'
or:
str = 'eureka! I found it and it costs eu250'
or:
str = 'eureka! I found it and it costs 250.00eur'
and so on..
I want to replace both 'eu' and 'eur' with 'euro' when they are followed and preceded by a non-char ([^a-z]) but I don’t want them to be victims of replacement. How do I accomplish that using sub or other methods?
First we compile an array we use as the set of test cases:
Next we try out the regexps:
Explanation:
\d+matches 1 or more digits (number)\s?matches zero or 1 whitespace\zmatches end of stringResult: