20
18

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 | Rubular で ruby の正規表現を検証しながら作成 #ruby #正規表現

Posted at

Ruby | Rubular で ruby の正規表現を検証しながら作成

概要

Rubular で ruby の正規表現を検証しながら作成します

Rubular とは?

Ruby の正規表現 Web エディタ。
Rubular

rubular1.png

利用サンプル

ケース1: シンプルな正規表現

/h.ge/ =~ 'hoge'
/h.ge/ =~ 'hige'
/h.ge/ =~ 'hage'
/h.ge/ =~ 'HoGe'

rubular2.png

ケース2: シンプルな正規表現(マッチせず)

/h.ge/ =~ 'noy match'

※no match にしたつもりがタイポしてた。再キャプチャがめんどかったのでそのまま。

rubular3.png

ケース3: グループ化

/^(.+?),(\d{1,3}?)$/ =~ "tanaka,23"
/^(.+?),(\d{1,3}?)$/ =~ "suzuki,43"
/^(.+?),(\d{1,3}?)$/ =~ "monster,1234"
/^(.+?),(\d{1,3}?)$/ =~ "not_exist_comma_line43"

rubular4.png

ケース4: 名前付きキャプチャ

/^(?<name>.+?),(?<age>\d{1,3}?)$/ =~ "tanaka,23"
/^(?<name>.+?),(?<age>\d{1,3}?)$/ =~ "suzuki,43"
/^(?<name>.+?),(?<age>\d{1,3}?)$/ =~ "monster,1234"
/^(?<name>.+?),(?<age>\d{1,3}?)$/ =~ "not_exist_comma_line43"

rubular5.png

参照

Rubular

20
18
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
20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?