i trying use non-capturing groups str_extract
function stringr
package. here example:
library(stringr) txt <- "foo" str_extract(txt,"(?:f)(o+)")
this returns
"foo"
while expect return only
"oo"
like in post: https://stackoverflow.com/a/14244553/3750030
how use non-capturing groups in r remove content of groups returned value while using matching?
when using regex (?:f)(o+)
won't capture match sure.
what capturing means storing in memory back-referencing, can used repeated match in same string or replacing captured string.
like in post: https://stackoverflow.com/a/14244553/3750030
you misunderstood answer. non-capturing groups doesn't means non-matching. it's captured in $1
( group 1 ) because there no group prior it.
if wish only match suppose b followed a should use positive lookbehind
this.
regex: (?<=f)(o+)
explanation:
(?<=f)
f
present behind following token won't match.(o+)
match , capture group (here in $1)if previous condition true.
Comments
Post a Comment