Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ... 
like image 744
flesh Avatar asked Jan 11 '09 13:01

flesh


People also ask

How do you match a word with a case-insensitive in regex?

Regular expression pattern matching may be case sensitive. To make a word or phrase case insensitive, use the regular expression /i . For example, /bad language/i will block all instances of "bad language", regardless of case.

How do you ignore a case in regex python?

re. IGNORECASE : This flag allows for case-insensitive matching of the Regular Expression with the given string i.e. expressions like [A-Z] will match lowercase letters, too. Generally, It's passed as an optional argument to re. compile() .

How do you grep a case-insensitive?

Case Insensitive Search By default, grep is case sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore case when searching, invoke grep with the -i option (or --ignore-case ).

Is regex case sensitive by default?

Case-Sensitive MatchBy default, regexpi performs case-insensitive matching. Use the regexp function with the same syntax as regexpi to perform case-sensitive matching. To disable case-sensitive matching for regexp , use the 'ignorecase' option.


2 Answers

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|..."

like image 135
Marc Gravell Avatar answered Sep 24 '22 01:09

Marc Gravell


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

Dim RegexObj As New Regex("([^.]+[.](jpg|jpeg|gif))", RegexOptions.IgnoreCase)
like image 43
Sebastian Dietz Avatar answered Sep 25 '22 01:09

Sebastian Dietz