我有以下多行的字符串。我不能把它变成一行,因为它来自命令输出。例如:
my $myString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also
the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s"
我想把这些东西去掉,包括“#34; scrambled"
我在下面试过,但似乎没有用。
if($myString =~ 's/.*(scrambled)//s')
{
print "Match: <$&>\n";
}
答案 0 :(得分:2)
id = 2 is test2
答案 1 :(得分:0)
尝试删除引号:
if($myString =~ s/.*(scrambled)//s)
使用引号尝试匹配文字s/.*(scrambled)//s
而不尝试更改任何内容。如果没有引号,将会看到“s”的替代品。
答案 2 :(得分:-1)
使用可以使用
pre
&amp;post
。
$myString =~ s/\bscrambled\b//ig && print $`.$';
或者
if($myString =~ s/\bscrambled\b//s)
{
print "Pre: <$`>\n";
print "Match: <$&>\n";
print "Post: <$'>\n";
}