What would be a regex that matches "nl" OR "fr" (without the quotes) but nothing else, case insensitive?
+3
A:
Give this a try:
^(nl|fr)$
And use the case i
nsensitive flag.
And I assume you meant nl or fr, and not nlfr.
jasonbar
2010-03-09 14:42:33
+3
A:
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])$
Jonathan Feinberg
2010-03-09 14:43:39
[nN][lL]|[fF][rR], dude that's sick! +1 anyway :)
Diadistis
2010-03-09 14:46:23
+2
A:
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"
ghostdog74
2010-03-09 15:22:36