简体   繁体   中英

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

  • abc@Test.com
  • abc@TEST.com
  • abc@teSt.com

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.

Flags go at the end.

/regex/i

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

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");

简单明了,使用以下正则表达式。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM