I would like to catch the words
ferrari
, ferry
, and ferret
.
The regex can easily be:
/ferr(ari|y|et)/
However, I noticed a pattern: when you want to capture multiple alternatives of a single word, you can use the square bracket [wordsToCapture]
. For example, I would like to catch the words: vowel a
, vowel e
, vowel u
, vowel o
, vowel i
.
The regex can be: vowel [aeiou]
which has less noise than vowel (a|e|i|o|u)
So I tried using the square bracket to catch multiple alternatives of grouped words. However, the [...]
(square bracket) renders my capturing group (the (...)
round bracket) useless, meaning if I use this regex ferr[(ari)(y)(et)]
, it will instead match: ferr(
, ferra
, ferrr
, ferri
, and the list goes on for every one of the characters presented in the square bracket.
Is there a way to make it so that the capturing group brackets inside my square bracket to retain its special meaning, thus making my RegExp terser? Or is there another way to make it terser?