加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

匹配多行文本 /m用法

发布时间:2020-12-16 00:40:40 所属栏目:大数据 来源:网络整理
导读:1 00:00:09,855 -- 00:00:14,724 Britain was an object of desire. 2 00:00:26,295 -- 00:00:31,847 Tacitus declared it worth the conquest, 3 00:00:32,015 -- 00:00:35,803 the best compliment that could occur to a Roman. 如果以句号为分割,把对应

1
00:00:09,855 --> 00:00:14,724
Britain was an object of desire.

2
00:00:26,295 --> 00:00:31,847
Tacitus declared it worth the conquest,

3
00:00:32,015 --> 00:00:35,803
the best compliment
that could occur to a Roman.
如果以句号为分割,把对应的时间合并起来,最后得到下面的结果:
1
00:00:09,724
Britain was an object of desire.
2
00:00:26,295 --> 00:00:35,803
Tacitus declared it worth the conquest,
the best compliment
that could occur to a Roman.

————————————————————————————————————————————————

?

#!/usr/bin/perl
#ans.pl
my $file;
while (<>){s/^/s+$//;$file.=$_};
my @data=split//./,$file;

for (@data){
??? /.*(^/d.*>.*/d$)/sm;? #由于@data中是按分段文本存放,所以需要用到多行匹配,/s表示匹配/n,/m多行匹配

??? my $time=$1;??? s/^/d+:.*/d$//gm;???? #删除时间行??? s/^/d+/n//gm;?????????? #删除数目行??? s/$/./;??????????????????????? #加上点号??? s//n+//n/g;???????????????? #删除空行??? print ++$num,"/n",$time,$_,"/n";}=====================perl? ans.pl? yourfile.txt

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读