Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match "True" or "False"

I need to create Regular Expression validator which will need to match a text "True" or "False" (Case Insensitive).

I have tried the following regex

^(True|False|TRUE|FALSE)$

Is this correct? but there is problem in Case Sensitive.

Edit

I have tried regex in following answers but it's not firing, because of ?i

like image 799
Vignesh Kumar A Avatar asked Apr 18 '14 06:04

Vignesh Kumar A


1 Answers

With a small optimization:

^(?:tru|fals)e$

Since (?i) is not validating, we'll set the case insensitivity in the code.

For any future reader who needs the code:

Dim FoundMatch As Boolean
Try
    FoundMatch = Regex.IsMatch(SubjectString, "^(?:tru|fals)e$", RegexOptions.IgnoreCase)
Catch ex As ArgumentException
    'Syntax error in the regular expression
End Try
like image 57
zx81 Avatar answered Sep 17 '22 20:09

zx81