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

perl-split()但是保留分隔符

发布时间:2020-12-15 21:30:40 所属栏目:大数据 来源:网络整理
导读:我从来没有使用过Perl,我有一个基本的问题. my $string1 = "Hi. My name is Vlad. It is snowy outside."; my @array = split('.' $string1); ##essentially I want this,but I want the period to be kept 我想将这个字符串拆分为’.’但我想保持这个时期.
我从来没有使用过Perl,我有一个基本的问题.
my $string1 = "Hi. My name is Vlad. It is snowy outside.";

 my @array = split('.' $string1); ##essentially I want this,but I want the period to be kept

我想将这个字符串拆分为’.’但我想保持这个时期.这怎么可以实现?

解决方法

您可以使用lookbehind来做到这一点:
split(/(?<=.)/,$string)

正则表达式匹配一段时间后的空字符串.

如果要同时删除句子之间的空格,可以将其更改为:

split(/(?<=.)s*/,$string)

正面和负面的lookbehind解释here

(编辑:李大同)

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

    推荐文章
      热点阅读