Tbpgr Blog

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

書籍 Regular Expressions Cookbook | Search Line by Line

パンくず

書籍 Regular Expressions Cookbook
Search Line by Line

概要

コマンドラインのように、各行に対して正規表現を行う方法について

サンプル

subject =<<"EOS"
one
two
three
EOS
lines = subject.split(/\r?\n/)
re = /two/
lines.each do |line|
  if line =~ re
     puts "true"
  else
     puts "false"
  end
end

出力

false
true
false