How do you achieve case insensitive regular expression patterns in JFlex.
Using the standard (?i:) notation does not seem to work.
For example:
To match the case insensitive word "class", the regex would be (?i:class).
But this doesn't work in a JFlex specification.
Use one of the directives:
From 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With