gpt4 book ai didi

regex - 不区分大小写的 JFlex 正则表达式

转载 作者:行者123 更新时间:2023-12-02 07:47:07 26 4
gpt4 key购买 nike

如何在 JFlex 中实现不区分大小写的正则表达式模式。

使用标准 (?i:) 表示法似乎不起作用。

例如:

To match the case insensitive word "class", the regex would be (?i:class).
But this doesn't work in a JFlex specification.

最佳答案

使用以下指令之一:

  • %无大小写
  • %忽略大小写

来自the manual :

This option causes JFlex to handle all characters and strings in the specification as if they were specified in both uppercase and lowercase form. This enables an easy way to specify a scanner for a language with case insensitive keywords. The string "break" in a specification is for instance handled like the expression ([bB][rR][eE][aA][kK]). The %caseless option does not change the matched text and does not effect character classes. So [a] still only matches the character a and not A, too. Which letters are uppercase and which lowercase letters, is defined by the Unicode standard and determined by JFlex with the Java methods Character.toUpperCase and Character.toLowerCase. In JLex compatibility mode (-jlex switch on the command line), %caseless and %ignorecase also affect character classes.

关于regex - 不区分大小写的 JFlex 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12945929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com