I'm trying with the following Regex:
/^[aeiou]\..*[aeiou]$/
But it's not working, I tested "abcda" and didn't match.
I'm trying with the following Regex:
/^[aeiou]\..*[aeiou]$/
But it's not working, I tested "abcda" and didn't match.
Regex for word start and end with vowel.
^[aeiou].*[aeiou]$
Regex for word start and end with same vowel.
^[a].*[a]$|^[e].*[e]$|^[i].*[i]$|^[o].*[o]$|^[u].*[u]$
/^(a|e|i|o|u).*\1$/
This works for me.
Explanation:
When you put ^ character, then you indicate that you are verifying the string for the start. The parentheses are group separators.
So, when putting (a|b|c) you are telling that the first group to be tested will match with a, b, or c. In the example, it marks as group (a|e|i|o|u). That means the string must start with any of those characters.
The | character acts as a boolean OR comparator.
The . indicates that any character except new line will be evaluated.
The * indicates that we are expecting 0 or more characters that match.
The \1 acts as a reference from the result of the first group, in this case (a|e|i|o|u).
The $ character indicates the end of the string or the end of the line if we decide to go with multiline flag (/m).
\b[aeiou](\w*[aeiou])?\b
\b stands for word boundary (in this case, beginning and ending of word). The optional grouping ()? is there to match single vowel words (very important for languages like portuguese with words like o, a and e or even the english word I.).
\b(?<vowel>[aeiou])(\w*\k<vowel>)?\b
Don't try to replace <vowel> for some value. It´s there just for capturing the matched vowel.
you can try this.
var re = /^([a,e,i,o,u]).*\1$/;
*\1 backreference and $ is used for the end.
Actually none of the existing answers was covering the corner case of having single vowel.
/^[aeiou]$|^[aeiou].*[aeiou]$/
Breakdown explanation:
^[aeiou]$
^ - start of a string[aeiou] - exactly one vowel.$ - end of a string.| - OR:^[aeiou].*[aeiou]$
^ - start of a string[aeiou] - exactly one vowel..* any - zero or more[aeiou] - exactly one vowel$ - end of a string.e.g match aba, but not match abe. We can backtrack to the first vowel:
/^[aeiou]$|^([aeiou]).*\1$/
The regular expression for words beginning and ending with the same vowel is:
var re = /(\ba(\w+)a\b|\be(\w+)e\b|\bi(\w+)i\b|\bo(\w+)o\b|\bu(\w+)u\b)/g;
While the regular expression for words beginning and ending with the any vowel is:
var re = /\b[aeiou]\w+[aeiou]\b/gi;
Okay if someone is looking for regex "end and start with same vowel" this is the code.
/^([a|e|i|o|u]).*\1$/