我正试图在R中做一个lookbehind正则表达式来找到一个模式.我希望这会在'bob'中拉出'b',但我得到一个错误.
> regexpr("(?<=a)b","thingamabob")
Error in regexpr("(?<=a)b", "thingamabob") :
invalid regular expression '(?<=a)b', reason 'Invalid regexp'
Run Code Online (Sandbox Code Playgroud)
这不会引发错误,但它也找不到任何错误.
> regexpr("(.<=a)b","thingamabob")
[1] -1
attr(,"match.length")
[1] -1
attr(,"useBytes")
[1] TRUE
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为regexpr的帮助页面明确指出lookbehind应该有效:http://stat.ethz.ch/R-manual/R-patched/library/base/html/regex.html
有任何想法吗?