在r中的最后一个图案的最后一次出现之后,删除字符串中的所有字符
我想在字符串中的特定模式的最后一个特定模式之后删除所有
。
字符 代码>
我想在模式的最后一次出现之后删除所有内容“ ge” < /code>,最终以:
“ asdsads dfdsfd&gt; x 442 /&lt; sdasvre(geqwe)ge ge ge ge ge ge ge ge ge ge''
。
I want to remove all the characters after the last ocurrence of a specific pattern in a string, in R.
For example:
string = "asdsads dfdsfd>x 442 /<sdasvre (geqwe) ge ge ge regthyty "
I would like to remove everything after the last ocurrence of the pattern "ge"
and end up with:
"asdsads dfdsfd>x 442 /<sdasvre (geqwe) ge ge ge"
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用捕获组在最后一个“ GE”(
^(。*GE)
)之前捕获所有字符串,并将整个内容替换为该捕获组(\\ 1 )。
You can use a capture group to capture all strings before the last "ge" (
^(.*ge)
), and replace that whole thing with that capture group (\\1
).您可以在这里使用负面的lookahead:
You could use a negative lookahead here: