0
1

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-09-19

よく使う正規表現です。
参考として使ってください。
引き続き更新~~~

  • 数字表現
3桁の数字 : ^\d{3}$
最低3桁の数字:^\d{3,}$
3桁~6桁までの数字:^\d{3,6}$
0か0以外で始まる数字:^(0|[1-9][0-9]*)$
  • 文字列表現
漢字 : \u3400-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF
ひらがな : \u3041-\u3096
かたがな : \u30A1-\u30FA
半角英字列 : [a-zA-Z]+
半角・全角英字列 : [a-zA-Za-zA-Z]+
全角文字 : [^\x01-\x7E]+
英字と数字 : ^[A-Za-z0-9]+$
半角または全角のスペース : [\s ]
3~20桁の任意の文字列 : ^.{3,20}$
英字の文字列 : ^[A-Za-z]+$
数字、英字、アンダーバーの文字列 : ^\w+$ (または^[A-Za-z0-9_]+$)
ダブルコーテーションで囲まれた部分 : \x22(.+?)\x22*
行末から / 以外の文字列 : [^/]+$
~を含まないの文字列(~を含まれる文字列禁止) : [^~\x22]+
^%&',;=?$\"を許可する文字列 : [^%&',;=?$\x22]+

※ \x22  とは " です

  • 特殊表現
XMLファイル : ^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
空白行 (空白行削除時に使う): \n\s*\r
郵便番号(例:1234567) : ^\d{7}$
郵便番号(例:123-4567) : ^\d{3}-\d{4}$
電話番号(例:0001112222) : ^0\d{9,10}$  
電話番号(例:000-1111-2222): ^0\d{2,3}-\d{1,4}-\d{4}$
暗証番号(弱) (アルファベットで始まり、半角6けた以上18けた以内でアルファベット、数字とアンダーバー) :
 ^[a-zA-Z]\w{5,17}$
暗証番号(強) : 
日付(弱)(例:2021-09-27) : ^\d{4}-\d{1,2}-\d{1,2}
日付(月) (例:01~09か1~12) : ^(0?[1-9]|1[0-2])$
日付(日) (例:01~09か1~31)  : ^((0?[1-9])|((1|2)[0-9])|30|31)$
毎月の25日にマッチ (例:2014-1-25) : \d{4}-\d{1,2}-25
URL  : ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
ドメイン  : [a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
Email : ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
HTMLタグ : <TABLE.*?>
IPアドレス : \d+\.\d+\.\d+\.\d+
IPアドレス : ((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
IPv4 : \\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b
IPv6 : (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])) 

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?