在 ruby 中将字符串视为多行的正则表达式

regular expression to treat string as mutiple line in ruby

我是 ruby 的新手。我对数据需要匹配模式的点感到震惊。我想知道是否有一个正则表达式使 ruby 将字符串视为多行。

我认为您正在寻找 m 选项。 m 将允许 . 匹配一个新行。

a = "this is my
string"
 => "this is my\nstring" 

a
 => "this is my\nstring" 

a.match /my.string/m
 => #<MatchData "my\nstring"> 

a.match /not my.string/m
 => nil