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

正则表达式 – R字符串删除拆分时的标点符号

发布时间:2020-12-14 06:27:26 所属栏目:百科 来源:网络整理
导读:假设我有一个字符串,例如以下内容. x - 'The world is at end. What do you think? I am going crazy! These people are too calm.' 我只需要在标点符号上拆分!?并跟随空白并保持标点符号. 这会删除标点符号并在分割部分中留下前导空格 vec - strsplit(x,'
假设我有一个字符串,例如以下内容.
x <- 'The world is at end. What do you think?   I am going crazy!    These people are too calm.'

我只需要在标点符号上拆分!?并跟随空白并保持标点符号.

这会删除标点符号并在分割部分中留下前导空格

vec <- strsplit(x,'[!?.][:space:]*')

如何分割留下标点符号的句子?

您可以使用perl = TRUE打开 PCRE并使用lookbehind断言.
strsplit(x,'(?<![^!?.])s+',perl=TRUE)

正则表达式:

(?<!          look behind to see if there is not:
 [^!?.]       any character except: '!','?','.'
)             end of look-behind
s+           whitespace (n,r,t,f,and " ") (1 or more times)

Live Demo

(编辑:李大同)

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

    推荐文章
      热点阅读