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 matches yes @ beginning of string, match yes in yes, man...
  • ^no matches no @ beginning of string, match no in no way!
  • ^$ matches empty string

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -