RegEx Ignore Case

后端 未结 3 1056
慢半拍i
慢半拍i 2020-12-05 22:46

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$/;


        
相关标签:
3条回答
  • 2020-12-05 23:15

    Flags go at the end.

    /regex/i
    

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

    0 讨论(0)
  • 2020-12-05 23:28

    Simple and straightforward, use following regex expression.

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

    0 讨论(0)
  • 2020-12-05 23:29

    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");
    
    0 讨论(0)
提交回复
热议问题