Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
那些知道答案的人的快速问题......代表“^”(帽子符号)的正则表达式模式是什么?这样我可以在执行以下操作时将其删除?
gsub("^","","^GSPC")
即上面的输出并不GSPC像预期的那样......
GSPC
您需要转义^,因为它是一个正则表达式元字符(如评论中的@Roman 注释)
^
gsub("\\^","","^GSPC")
每当您只想匹配文字字符串时,您可以设置fixed = TRUE然后键入字符串“verbatim”。它使pattern参数更具可读性,并且启动速度更快!
fixed = TRUE
pattern
gsub("^", "", "^GSPC", fixed = TRUE) # [1] "GSPC"