Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx Ignore Case

I've been trying to create a regex which would ignore the casing.

This is the regex i am trying to use:

/^[A-Za-z0-9._+\-\']+@+test.com$/; 

So basically i would want to match any of these

I tried this, but it doesn't work:

/^[A-Za-z0-9._+\-\']+@+(?i)+test.com$/; 

I read somewhere about the use of (?i), but couldn't find any examples which show their usage in regex to ignore casing. Thoughts anyone ? Thanks a lot in advance.

like image 258
Nanu Avatar asked Jun 24 '14 20:06

Nanu


People also ask

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.

Is regex case-sensitive in Python?

Search patterns are made up of a sequence of characters and can be specified using regex rules. However, to work with regular Python expressions, you first need to import the re module. Case insensitive means that the text should be considered equal in lowercase and uppercase.

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


2 Answers

Flags go at the end.

/regex/i 

i is for case-Insensitive (or ignore-case)

like image 135
Mathletics Avatar answered Oct 07 '22 03:10

Mathletics


For anyone else who arrives here looking for this, if you've got code that is using the RegExp constructor you can also do this by specifying flags as a second argument:

new RegExp(pattern[, flags]) 

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp

For example:

var pattern = /^[A-Za-z0-9._+\-\']+@+test.com$/; var regExp = new RegExp(pattern, "i"); 
like image 34
garryp Avatar answered Oct 07 '22 02:10

garryp