1
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?

More than 3 years have passed since last update.

全角漢字・かな・半角英字のみ25文字以内の正規表現

Last updated at Posted at 2021-06-14

はじめに

Pythonのシステムで名前の入力が妥当か調べる必要があり思いついたコードです。

コード

import re
# 漢字
p1 = re.compile('[\u2E80-\u2FDF\u3005-\u3007\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\U00020000-\U0002EBEF]*')
# ひらがな
p2 = re.compile('[\u3041-\u309F]*')
# 半角英字
p3 = re.compile('[a-zA-Z]*')
# 文字数1~25
p4 = re.compile('.{1,25}')
# 今回の
p5 = re.compile('[\u2E80-\u2FDF\u3005-\u3007\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\U00020000-\U0002EBEF\u3041-\u309Fa-zA-Z]{1,25}')


if p5.fullmatch('佐藤Michaelしんご'):
    print("ok")
else:
    print("out")

終わりに

Python楽しい

1
0
1

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
1
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?