sub(≒replace)
文字列の指定部分を別の文字列に置換。
gsub
文字列の指定部分を全て別の文字列に置換。
str = "aaabbb"
str.sub(/bbb/,"BBB")
# aaaBBB
str.gsub(/b/,"B")
# aaaBBB
match
検索したい文字が含まれているかどうか。
見つかれば、検索文字リピート
見つからないなら、nil
str = "aaabbb"
str.match("ab")
# ab
検索条件
- [a-z] a,b,c,d・・・x,y,zのいずれかの文字にマッチ。
- \d 数字にマッチ
- {n, m} 直前の文字が最低n回、最高m回出現
- i 大文字・小文字を区別しない
- . あらゆる1文字
- 直前文字の1回以上の繰り返し
複合条件可。