B)A" 我想删除所有标点符号和紧跟在 > 之后的字母,即 >B 这是我想要的输出: output = "AAA" 我尝试使用 gsub-6ren">
gpt4 book ai didi

R 正则表达式 : removing only the immediate following character after >

转载 作者:行者123 更新时间:2023-12-04 22:42:02 26 4
gpt4 key购买 nike

我在 R 中有以下字符串:

string1 = "A((..A>B)A"

我想删除所有标点符号和紧跟在 > 之后的字母,即 >B
这是我想要的输出:
output = "AAA"

我尝试使用 gsub()如下:
output = gsub("[[:punct:]]","", string1)

但这给 AABA , 保留紧随其后的字符。

最佳答案

这将首先使用您的工作加上领先的后视来查找 > 之后的内容。特点。

gsub('(?<=>).|[[:punct:]]', '', "A((..A>B)A", perl=TRUE)
## [1] "AAA"

关于R 正则表达式 : removing only the immediate following character after >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45150409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com