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?

More than 5 years have passed since last update.

Rubyの正規表現で〇〇回以上繰り返されたことを確認する

Posted at

{n,}を使う。
n回以上(nは数字)にマッチする。

5桁の数字に対して確認。

5桁以上

 pry(main)> "12345".match(/[1-9]{5,}/)                                                                                                                                                 
=> #<MatchData "12345">

6桁以上

pry(main)> "12345".match(/[1-9]{6,}/)                                                                                                                                                 
=> nil
  • {,m} m回以下(mは数字)
  • {n} ちょうどn回(nは数字)
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?