Possible Confusion: Match Single Character with Multiple Possibilities

Possible Confusion: Match Single Character with Multiple Possibilities
0

#1

In the challenge Regular Expressions: Match Single Character with Multiple Possibilities, the example code shows

let bgRegex = /b[aiu]g/;

which would normally work. However, the solution,

let vowelRegex = /[aeiou]/gi;

requires the global and ignore case flags to be outside the literal regex.

If done as

let vowelRegex = /[aeiou]gi/;

an empty array is returned.

I thought I would mention this in case someone was confused on what to do.


#2

That g in the example is not the general flag, but the letter "g".
/b[aiu]g/ will match bag, big or bug, whereas /b[aiu]g/g will match all the occurences.

/[aeiou]gi/ this will match the first occurence of agi, egi, igi, oig or ugi.

This tool is nice to test your regex: https://regexr.com/

:slight_smile:


#3

I see now. Regex has always been confusing but with the additions to the curriculum, it seems easier. Thanks for the recommendation of the tool too!