Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a regular expression match upper and lower case?

Tags:

I don't really know much about regex at all, but if someone could help me change the following code to also allow for lowercase a-z, that would be great!

$("input.code").keyup(function(){     this.value = this.value.match(/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/)[0]; }); 
like image 883
SoulieBaby Avatar asked Sep 14 '11 04:09

SoulieBaby


People also ask

How do you match a regular expression?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).

What is difference [] and () in regex?

[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.

How do you match a character after regex?

Method 1: Match everything after first occurence Whitespace characters include spaces, tabs, linebreaks, etc. while non-whitespace characters include all letters, numbers, and punctuation. So essentially, the \s\S combination matches everything. It's similar to the dot character (.)


1 Answers

If you want a regular expression to be case-insensitive, add a i modifier to the end of the regex. Like so:

/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/i 
like image 171
cheeken Avatar answered Sep 29 '22 17:09

cheeken