LoginSignup
0
1

正規表現でカンマ区切りの数字を判定する

Last updated at Posted at 2022-02-21

IDを引数にする処理の入力チェックなど、以下のような要件を満たす正規表現を書く機会があったのでメモ

  • 1以上の任意の整数
  • カンマ区切り
  • 個数は任意
  • それぞれの値がゼロ始まりでない
^[1-9][0-9]*(,[1-9][0-9]*)*$

11,2,3は許可(マッチ)
0, 01, 1.2.3, 1,2,3,などは拒否(アンマッチ)

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