How to match a string, but case-insensitively?

前端 未结 5 928
渐次进展
渐次进展 2020-12-29 05:59

Let\'s say that I want to match \"beer\", but don\'t care about case sensitivity.

Currently I am defining a token to be (\'b\'|\'B\' \'e\'|\'E\' \'e\'|\'E\' \'r\'|

5条回答
  •  佛祖请我去吃肉
    2020-12-29 06:33

    I would like to add to the accepted answer: a ready -made set can be found at case insensitive antlr building blocks, and the relevant portion included below for convenience

    fragment A:('a'|'A');
    fragment B:('b'|'B');
    fragment C:('c'|'C');
    fragment D:('d'|'D');
    fragment E:('e'|'E');
    fragment F:('f'|'F');
    fragment G:('g'|'G');
    fragment H:('h'|'H');
    fragment I:('i'|'I');
    fragment J:('j'|'J');
    fragment K:('k'|'K');
    fragment L:('l'|'L');
    fragment M:('m'|'M');
    fragment N:('n'|'N');
    fragment O:('o'|'O');
    fragment P:('p'|'P');
    fragment Q:('q'|'Q');
    fragment R:('r'|'R');
    fragment S:('s'|'S');
    fragment T:('t'|'T');
    fragment U:('u'|'U');
    fragment V:('v'|'V');
    fragment W:('w'|'W');
    fragment X:('x'|'X');
    fragment Y:('y'|'Y');
    fragment Z:('z'|'Z');
    

    So an example is

       HELLOWORLD : H E L L O W O R L D;
    

提交回复
热议问题