Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

書籍 Regular Expressions Cookbook | Retrieve a List of All Matches

パンくず

書籍 Regular Expressions Cookbook
Retrieve a List of All Matches

概要

マッチした内容全体をリストで取得

構文

# 戻り値はヒットした件数分のリストになる
ret = "reg".scan(/regexp/)

サンプル

subject = "hoge hige hage"
result = subject.scan(/h[aoi]ge/) # はげ、ほげ、ひげにマッチ
puts result.class #=>Array
puts result.to_s #=>["hoge", "hige", "hage"]