gpt4 book ai didi

linux - 删除包含多行字符串中单词的内容

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:28 25 4
gpt4 key购买 nike

我有以下多行字符串。我不能把它写成一行,因为它来自命令输出。例如:

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"

我想去掉包括“scrambled”这个词在内的内容

我试过下面但似乎不起作用。

if($myString =~ 's/.*(scrambled)//s')
{
print "Match: <$&>\n";
}

最佳答案

#!/usr/bin/perl
use strict;
use warnings;

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";

$myString =~ s/.*\bscrambled\b//s;

print $myString;

Demo

关于linux - 删除包含多行字符串中单词的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39228363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com