Regex: ignore case sensitivity

后端 未结 13 1835
孤城傲影
孤城傲影 2020-11-22 06:11

How can I make the following regex ignore case sensitivity? It should match all the correct characters but ignore whether they are lower or uppercase.

G[a-b]         


        
13条回答
  •  长发绾君心
    2020-11-22 06:54

    Depends on implementation but I would use

    (?i)G[a-b].
    

    VARIATIONS:

    (?i) case-insensitive mode ON    
    (?-i) case-insensitive mode OFF
    

    Modern regex flavors allow you to apply modifiers to only part of the regular expression. If you insert the modifier (?im) in the middle of the regex then the modifier only applies to the part of the regex to the right of the modifier. With these flavors, you can turn off modes by preceding them with a minus sign (?-i).

    Description is from the page: https://www.regular-expressions.info/modifiers.html

提交回复
热议问题