検索データを抽出
Top > Ruby [2.2.2] > grep / scan
test = ["acha", "porute", "piipo", 501]
p test.grep("porute") # ["porute"]
p test.grep("ac") # []
p test.grep(/^a.*/) # ["acha"]
p test.grep(/p.*/) # ["porute", "piipo"]
p test.grep(/.*o$/) # ["piipo"]
p test.grep(String) # ["acha", "porute", "piipo"]
p test.grep(Numeric) # [501]
test = "achaporutepiipo501"
p test.scan("porute") # ["porute"]
p test.scan("ac") # ["ac"]
p test.scan(/^a.*/) # ["achaporutepiipo501"]
p test.scan(/p.*/) # ["porutepiipo501"]
p test.scan(/.*o$/) # []
p test.scan(String) # `scan': wrong argument type Class(expected Regexp) (TypeError)
p test.scan(Numeric) # `scan': wrong argument type Class(expected Regexp) (TypeError)