解析r中sub和gsub的正则表达式
我很难理解下面几行代码中的正则表达式是什么意思解析r中sub和gsub的正则表达式,r,regex,gsub,R,Regex,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
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))
author=“10_1 A Kumar;Ahmed Hemani;JohnnyÖ;berg好吧。有很多问题。首先要做的事
sub(“.*”,“”,作者)
查找。
以及之后的所有内容。因此,在您的案例中,.*
对应于\u 1 Kumar;Ahmed Hemani;JohnnyÖ;Berg在这里输入这些内容@rawr我应该选择哪种口味?似乎所有这些内容都显示了一个错误。我没有得到一个错误,可能是因为不需要的双\你用这个吗website@rawr绝对奇妙。以下是正确的:.*
查找.
之后的所有内容并对其进行操作,.*.
查找.
之前的所有内容并对其进行操作,^.*.
从一开始就查找,直到找到指定的内容(在我的例子中,\\s
,一个空格)并对其进行操作?@简短的回答是肯定的。