regex - Optionality and "or" in capturing groups in perl -
i want capturing group in regex has several "or"s , optional group. my regex: (a|e|i|o|u)?(a|e|i|o|u)(g|k) want find 1 or 2 vowels before g or k - "taek" , "tag".
i tried putting parenthesis around (a|e|i|o|u)?(a|e|i|o|u) $1 still uninitialized.
$1 unset if optional first capture doesn't match anything; doesn't imply $2 unset. if want $1 empty instead, need wrap brackets around it, i.e. ([aeiou]?). in if needed use alternation , optional indicator need 2 levels of brackets, , case you'd want turn capturing off inner 1 "?:", i.e. ((?:a|e|i|o|u)?).
Comments
Post a Comment