我无法理解以下代码行中正则表达式的含义。在r中解析sub和gsub的正则表达式
author = "10_1 A Kumar; Ahmed Hemani ; Johnny Öberg<"
# after some experiment, it looks like this line captures whatever is in
# front of the underscore.
authodid = sub("_.*","",author)
# this line extracts the number after the underscore, but I don't know
# how this is achieved
paperno <- sub(".*_(\\w*)\\s.*", "\\1", author)
# this line extracts the string after the numbers
# I also have no idea how this is achieved through the code
coauthor <- gsub("<","",sub("^.*?\\s","", author))
我已经在网上看到第一个参数是模式,第二个是替换,第三个是对象操作。我也在SO上看到了一些帖子,并得知\\w
表示一个字,\\s
是一个空格。
但是,有几件事情还不清楚。 \\w
表示单词,是否表示下一个单词?如果不是,我应该如何解释?我了解到^
匹配字符串的开始,但^
之后的那段时间呢?
更重要的是,什么是_.*
的解释.*_
^.*?\\s
怎么样?我应该如何阅读它们?
谢谢!
在这里键入这些东西https://regex101.com – rawr
@rawr我应该选择哪种味道?似乎所有人都显示错误。 – Waht
[pcre应该没问题](https://regex101.com/r/sIb7Ql/1),我没有得到一个错误,也许你是因为双\这是不需要的,当你使用这个网站 – rawr