Skip to content

Instantly share code, notes, and snippets.

@satou-haruka-37
Created January 29, 2024 03:23
Show Gist options
  • Save satou-haruka-37/4a3d6ce76cf908c48936f5834b896afa to your computer and use it in GitHub Desktop.
Save satou-haruka-37/4a3d6ce76cf908c48936f5834b896afa to your computer and use it in GitHub Desktop.
Ruby Silver 正規表現
# 正規表現の中の.は任意の1文字を表す。下記の場合oの後に4文字続く。
p "hogehogehoge".slice(/o..../)
#=> "ogeho"
# 最初のハイフンは範囲指定(2-4、234のどれかにマッチ)で、末尾のハイフンは「-」という文字
# スラッシュで囲まれていなくても、deleteメソッドなどの引数では文字列内で正規表現のような指定方法が使用できる。
p "0123456789-".delete("^12-46-")
#=> "12346-"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment