tags:

views:

73

answers:

4
+1  Q: 

simple regex match

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 insensitive flag.

And I assume you meant nl or fr, and not nlfr.

jasonbar
+1  A: 

That's:

(nl|fr)
Konrad Garus
+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
[nN][lL]|[fF][rR], dude that's sick! +1 anyway :)
Diadistis
+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