I have problem with regex. I want to match only these words which contains only vowel or consonants.
For example I have strings like this:
aeyiuo
aeYYuo
qrcbk
aeeeee
normal
Text
extTT
My regex should match: aeyiuo aeYYuo aeeeee
I don't know why my expression doesn't work ^[aeyiuo]*|[^aeyiuo]*$
To check my regexp I use online parsers: http://www.regexr.com/ or http://regexpal.com/
If somebody could explain me my mistake, I would be very grateful.
If you want to match lines with only vowels then you just need to think about a character class []
.
What should we add to it ? Vowels ! [aeiouy]
.
We need it one or more times, so let's add a plus sign to it [aeiouy]+
.
We also need to anchor it ^[aeiouy]+$
.
Now let's talk about the modifiers, we need the i
modifier to match case insensitive. We also need the m
modifier so that ^
and $
will match begin of line and end of line respectively. Also don't forget the g
modifier, in some engines you need it to match all occurences.
Online demo
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