How do I do a case insensitive regular expression in Go?

后端 未结 4 1141
粉色の甜心
粉色の甜心 2020-12-12 18:36

Now, of course, I could write my regular expression to handle both cases, such as regexp.Compile(\"[a-zA-Z]\"), but my regular expression is constructed from a

4条回答
  •  Happy的楠姐
    2020-12-12 19:36

    Use the i flag. Quoting the tip documentation:

    Grouping:

    (re)           numbered capturing group
    (?Pre)   named & numbered capturing group
    (?:re)         non-capturing group
    (?flags)       set flags within current group; non-capturing
    (?flags:re)    set flags during re; non-capturing
    

    Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:

    i              case-insensitive (default false)
    m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
    s              let . match \n (default false)
    U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
    

提交回复
热议问题