「Ruby」正規表現式のサンプル

書式
~ /文字列(.*)/ )
使用例

#!/usr/bin/ruby

cftA = "Cats are smarter than dogs";
cftB = "Dogs also like meat";

if ( cftA =~ /Cats(.*)/ )
  puts "文字列A contains Cats"
end
if (cftB =~ /Cats(.*)/ )
  puts "文字列B contains  Dogs"
end

実行結果
文字列A contains Cats

Ruby

Posted by arkgame