Regular Expressions, containing specific words

47 Views Asked by At

I need to specify that my user name has to start with one of two words, followed by a backslash. It can only accept the words cat or dog at the beggining and then a backslash is expected, for example:

  cat\something
  dog\something

Both are accepted. What's the regular expression for this? I've tried some regular expressions but I haven«t figured it out yet.

1

There are 1 best solutions below

0
metmo On BEST ANSWER

The solution is:

^cat\\.*|^dog\\.*

https://regex101.com/ is a great tool for testing and evaluating regular expressions.