作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目的:
我想将句子与单词“no”匹配,但前提是在 r 中“no”之前没有“with”或“there is”或“there are”。
输入:
The ground was rocky with no cracks in it
No diggedy, no doubt
Understandably, there is no way an elephant can be green
The ground was rocky with no cracks in it
Understandably, there is no way an elephant can be green
gsub(".*(?:((?<!with )|(?<!there is )|(?<!there are ))\\bno\\b(?![?:A-Za-z])|([?:]\\s*N?![A-Za-z])).*\\R*", "", input_string, perl=TRUE, ignore.case=TRUE)
最佳答案
你只需要有一个正则表达式交替字符。想法是匹配并捕获所有可能的“否”句子并匹配所有剩余的句子。然后用 \\1
替换所有匹配的字符即,来自第一个捕获组的字符。
gsub("(?i)(.*(with|there (?:is|are)) no\\b.*)|.*", "\\1" ,string, perl=T)
x <- "The ground was rocky with no cracks in it\nNo diggedy, no doubt\nUnderstandably, there is no way an elephant can be green"
gsub("(?i)(.*(with|there (?:is|are)) no\\b.*\\n?)|.*\\n?", "\\1" ,x, perl=T)
# [1] "The ground was rocky with no cracks in it\nUnderstandably, there is no way an elephant can be green"
关于r - 如何在后视中使用交替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47010713/
我正在尝试获得一个按钮,按下该按钮时会改变颜色。当再次按下时,它应该变回原来的颜色。我究竟做错了什么? 我的模板中的按钮: export default { data: {
我是一名优秀的程序员,十分优秀!