flesh
flesh

Reputation: 23935

How can I ignore case in a regex?

I have an ASP.NET RegularExpressionValidator that checks file extensions. Is there a quick way I can tell it to ignore the case of the extension without having to explicitly add the upper case variants to my validation expression?

ValidationExpression="([^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ... 

Upvotes: 13

Views: 32502

Answers (3)

Marc Gravell
Marc Gravell

Reputation: 1062780

Server-side, "(?i)" can be used, but this doesn't work client-side. See here for more discussion and workaround.

i.e. "...(?i)(jpg|jpeg|gif|png|wpf|..."

Upvotes: 24

Michael Stum
Michael Stum

Reputation: 180944

According to the Regular Expression Options, this should work:

// Added LowerCase i:
ValidationExpression="(?i:[^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ...

Upvotes: 1

Sebastian Dietz
Sebastian Dietz

Reputation: 5706

In VisualBasic.NET, you can use the RegExOptions to ignore he case:

Dim RegexObj As New Regex("([^.]+[.](jpg|jpeg|gif))", RegexOptions.IgnoreCase)

Upvotes: 2

Related Questions