📜  ruby 匹配字符串中的单词 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:47.110000             🧑  作者: Mango

代码示例1
text = "A regular expression is a sequence of characters that define a search pattern."

puts 'Found "A" at the beginning of the string.' if text.match(/^A/)
puts 'Found "O" at the beginning of the string.' if text.match(/^O/)

puts 'Found the string "character".' if text.match(/character/)
puts 'Found the word "character".' if text.match(/character\b/)