0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaで「CANON_EQフラグ(パターンと対象の文字がUnicode正規等価であればマッチする)」の動作を確認してみた

Last updated at Posted at 2024-11-21

概要

Javaで「CANON_EQフラグ(パターンと対象の文字がUnicode正規等価であればマッチする)」の動作を確認しました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

JSample24_1.java
import java.util.regex.*;

class JSample24_1{
  public static void main(String[] args){
    String target = "て\u3099は";

    String regex = "では";
    Pattern p1 = Pattern.compile(regex);

    Matcher m1 = p1.matcher(target);
    System.out.println(target + ":" + m1.find());

    System.out.println("---- ----");

    Pattern p2 = Pattern.compile(regex, Pattern.CANON_EQ);

    Matcher m2 = p2.matcher(target);
    System.out.println(target + ":" + m2.find());
  }
}

以下のコマンドを実行しました。

$ javac JSample24_1.java 
$ java JSample24_1 
では:false
---- ----
では:true

まとめ

何かの役に立てばと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?