This is my code so far: ([T|t][E|e][S|s][T|t])|([D|d][E|e][V|v])|([P|p][R|r][O|o][D|d])
这是我到目前为止的代码:([T | t] [E | e] [S | s] [T | t])|([D | d] [E | e] [V | v])|([ p | p] [R | R] [0 | O] [d | d])
I want to match only 1 of these set, example:
我想只匹配其中一个,例如:
- Test - Match
- Test Test - not match
- Test Dev - not match
测试 - 匹配
测试测试 - 不匹配
测试开发 - 不匹配
1 个解决方案
#1
2
You can simply use the following regex:
您可以简单地使用以下正则表达式:
/^(test|dev|prod)$/gim
Note the use of the i
modifier, that make the regex case insensitive.
注意使用i修饰符,使正则表达式不区分大小写。
^
and $
(m
modifier) are use to match the beginning and the end of the string, in order not to match test test
, etc.
^和$(m修饰符)用于匹配字符串的开头和结尾,以便不匹配测试测试等。
Test it on regex101
#1
2
You can simply use the following regex:
您可以简单地使用以下正则表达式:
/^(test|dev|prod)$/gim
Note the use of the i
modifier, that make the regex case insensitive.
注意使用i修饰符,使正则表达式不区分大小写。
^
and $
(m
modifier) are use to match the beginning and the end of the string, in order not to match test test
, etc.
^和$(m修饰符)用于匹配字符串的开头和结尾,以便不匹配测试测试等。