0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

正規表現メモ

Last updated at Posted at 2021-05-21

メモ

氏名のように全角のみ入力可としたい

文字プロパティを使う。

Editor等

test.sh
# 漢字
\p{Han} 
# カタカナ
\p{Katakana}
# ひらがな
\p{Hiragana}

Java

Isを付ければOK。

test.java
Pattern.compile("\\p{IsHan}");
Pattern.compile("\\p{IsKatakana}");
Pattern.compile("\\p{IsHiragana}");

半角カナは拒否したい。

Unicodeのレンジチェックを行う。
image.png

Editor等

test.sh
([\x{ff66}-\x{ff6f}]|[\x{ff71}-\x{ff9f}])

Java

test.java
Pattern.compile("([\uFF66-\uFF6F]|[\uFF71}-\uFF9F])");

\uFF66-\uFF6F

image.png

\uFF71}-\uFF9F

image.png
image.png

参考

Pattern Javadoc
[連載:正規表現] Unicode文字プロパティについて (3) 文字プロパティとは
Unicode Scripts-13.0.0.txt
図書館員のコンピュータ基礎講座 Unicode半角

0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?