regex - How to use alternation in character class -
without being specific particular programming language i've been looking @ regular expressions.
as understand alternative notation a|b
using character class [ab]
.
so if have regex ab|cd
reads a followed b or c followed d how can use character class this?
this assume wouldn't work: [abcd]
right answer: [(ab)(cd)]
- looks bit strange me reason.
character class alone match single character. here need use capturing or non-capturing group if want apply or group of characters.
(ab|cd)
or
(?:ab|cd)
Comments
Post a Comment