Created
January 29, 2024 03:23
-
-
Save satou-haruka-37/4a3d6ce76cf908c48936f5834b896afa to your computer and use it in GitHub Desktop.
Ruby Silver 正規表現
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 正規表現の中の.は任意の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