In what language/environment is this regex being implemented? Regex seems like unnecessary overhead in many situations.
– mickmackusa
2 Answers
580
votes
This will do:
/^(apple|banana)$/
to exclude from captured strings (e.g. $1,$2):
(?:apple|banana)
114
votes
There are different regex engines but I think most of them will work with this:
apple|banana
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more