POSIX Expression is giving me a headache.
Lets say we have a string:
a = "[question(37), question_pipe(\"Person10\")]"
and ultimately I would like to be able to have:
b = c("37", "Person10")
I’ve had a look at the stringr package but cant figure out how to extract the information out using regular expressions and str_split.
Any help would be greatly appreciated.
Cameron
So if I understand correctly you want to extract the elements within parenthesis.
You can first extract those elements, including the parenthesis, using
str_extract_all:Since
str_extract_allreturns a list, let’s turn it into a vector:Last, you can remove the parenthesis (the first and last character of each string) using
str_sub:Edit: A few comments about the regex pattern:
\\(and\\)are your opening and closing parenthesis..*?means any character string but without being greedy, otherwise you would get one long match from the first(to the last).