Regex to match only two specific words, e.g. Yes or No -
my attempt is:
^yes|^no|^$
but when use this, words other "yes" , "no" matched
how fix it?
i've been testing regex using this online regex tester.
try this:
^(?:yes|no)$
in vbscript, this:
dim myregexp, foundmatch set myregexp = new regexp myregexp.pattern = "^(?:yes|no)$" foundmatch = myregexp.test(subjectstring)
what problem?
you had alternation 3 options:
^yes
matchesyes
@ beginning of string, matchyes
inyes, man...
^no
matchesno
@ beginning of string, matchno
inno way!
^$
matches empty string
Comments
Post a Comment