My attempt is:
^Yes|^No|^$
but when I use this, words other than "Yes" and "No" are matched
How do I fix it?
I've been testing my regex using this online regex tester.
Try this:
^(?:Yes|No)$
In VBScript, something like this:
Dim myRegExp, FoundMatch
Set myRegExp = New RegExp
myRegExp.Pattern = "^(?:Yes|No)$"
FoundMatch = myRegExp.Test(SubjectString)
What was the problem?
You had an alternation with three options:
^Yes matches Yes at the beginning of the string, but will also match Yes in Yes, man...
^No matches No at the beginning of the string, but will also match No in No way!
^$ matches the empty string Below regex would match yes or no only,
^(?:Yes\b|No\b)
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With