What would 开发者_运维技巧be a regex that matches "nl" OR "fr" (without the quotes) but nothing else, case insensitive?
Alternatives in regular expressions are expressed as expressions separated by the |
character.
nl|fr
Case-insensitivity is specified in different ways, in different languages. One way that will work everywhere is to be explicit.
[nN][lL]|[fF][rR]
If you want "the whole string" to be one of those two phrases, then you must anchor it.
^([nN][lL]|[fF][rR])$
Give this a try:
^(nl|fr)$
And use the case i
nsensitive flag.
And I assume you meant nl or fr, and not nlfr.
with regex, (i
for case-insensitive)
/^(nl|fr)$/i
without regex, in your favourite language, just use the equality operator
mystring == "nl" or mystring == "fr"
That's:
(nl|fr)
精彩评论