Regular Expression Questions

Asked 1 years ago, Updated 1 years ago, 57 views

About regular expressions.
(y|yes|yes|ok|ok)
I only want it to be true when only is entered.
I don't want the year to be true.
Currently, we are looking to see if any of the above words are included in the message.
If you enter a spelling with y, it will react.
I don't want to react to this.
What should I do?

//measege is a variable that contains data from user input.
constyesExp=/(y|yes|yes|yes|ok|ok)/;
clearExp.test(measege)

javascript regular-expression

2022-09-30 19:40

1 Answers

Add the beginning and end of the string to your search criteria

/^(y|yes|yes|ok|ok)$/

Please say


2022-09-30 19:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.