简体   繁体   English

RegEx忽略大小写

[英]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 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. 我在某处读到了(?i)的使用,但是找不到任何显示它们在regex中用于忽略套管的例子。 Thoughts anyone ? 想什么? Thanks a lot in advance. 非常感谢提前。

Flags go at the end. 旗帜走到尽头。

/regex/i

i is for case-Insensitive (or ignore-case) i是针对案例 - 不敏感(或忽略案例)

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: 对于到达此处寻找此问题的其他任何人,如果您有使用RegExp构造函数的代码,您也可以通过将flags指定为第二个参数来执行此操作:

new RegExp(pattern[, flags])

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp 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$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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