gpt4 book ai didi

regex - 在字符串中查找 $ 的位置

转载 作者:行者123 更新时间:2023-12-01 07:39:31 24 4
gpt4 key购买 nike

基于这里的建议:Find location of character in string ,我试过这个:

> gregexpr(pattern ='$',"data.frame.name$variable.name")
[[1]]
[1] 30
attr(,"match.length")
[1] 0
attr(,"useBytes")
[1] TRUE

但它没有用;笔记:
> nchar("data.frame.name$variable.name")
[1] 29

如何找到 $的位置在这个字符串中?

最佳答案

问题是$是正则表达式中的字符串结束标记。试试这个:

> gregexpr(pattern ='\\$',"data.frame.name$variable.name")
[[1]]
[1] 16
attr(,"match.length")
[1] 1
attr(,"useBytes")
[1] TRUE

...给出正确答案 - 即 16 .

关于regex - 在字符串中查找 $ 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19214971/

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