javaregexjtablerowfilter

java rowfilter regex Locale


I have a populated JTable and have a case insensitive row filter:

RowFilter rf = RowFilter.regexFilter("(?i)"+filterText.getText(), 0);

This works fine until localized letter are used åäöÅÄÖ are entered in the JTextfield. The case insensitivity does not work with these letters.

Anyone knows how to make the regex filter working with localized letters?


Solution

  • Answering this per my comment:

    If you flag your Pattern with the UNICODE_CASE option alongside your case-insensitive option, you should get the results you require.

    Since this is a constructed pattern, just prepend (?iu) instead of only (?i).

    For reference, the documentation says the UNICODE_CASE flag...

    Enables Unicode-aware case folding.

    When this flag is specified then case-insensitive matching, when enabled by the CASE_INSENSITIVE flag, is done in a manner consistent with the Unicode Standard. By default, case-insensitive matching assumes that only characters in the US-ASCII charset are being matched.

    Unicode-aware case folding can also be enabled via the embedded flag expression (?u).

    Specifying this flag may impose a performance penalty.