I'd like to extract the name John Doe
from the following string:
str <- 'Name: | |John Doe |'
I can do:
library(stringr)
str_extract(str,'(?<=Name: \\| \\|).*(?= \\|)')
[1] "John Doe"
But that involves typing a lot of spaces, and it doesn't work well when the number of spaces is not fixed. But when I try to use a quantifier (+
), I get an error:
str_extract(str,'(?<=Name: \\| +\\|).*(?= +\\|)')
Error in stri_extract_first_regex(string, pattern, opts_regex = opts(pattern)) :
Look-Behind pattern matches must have a bounded maximum length. (U_REGEX_LOOK_BEHIND_LIMIT, context=`(?<=Name: \| +\|).*(?= +\|)`)
The same goes for other variants:
str_extract(str,'(?<=Name: \\|\\s+\\|).*(?=\\s+\\|)')
str_extract(str,'(?<=Name: \\|\\s{1,}\\|).*(?=\\s{1,}\\|)')
Is there a solution to this?