I am working on doubling all vowels in every word. For eg:
$string="if it rains, cover with umbrella";
Here is the code I wrote, but I am not getting correct output.
$string=~s/a|e|i|o|u/aa|ee|ii|oo|uu/gi; print $string;
Expected Output: iif iit raaiins cooveer wiith uumbreelaa
Can some one help me in this?
The regular expression in your substitution should work fine but, as you will have seen, the replacement string is a simple string that bears no relation to the match unless you capture substrings within the regular expression and use them in the replacement string.
Use a character class to match any one of a set of characters, like
[aeiuo].Use parentheses to ‘capture’ part of a match, so that you can use it in the replacement string.
output