I am facing a problem with regex and strsplit. I would like to split the following x
string based on the second :
symbol
x <- "26/11/19, 22:16 - Super Mario: It's a me: Super Mario!, but also : the princess"
然后获得像这样的东西
"26/11/19, 22:16 - Super Mario"
" It's a me: Super Mario!, but also : the princess"
I am using by using strsplit
with the following regular expression that in based on my little know-how should reason like "select ONLY the colon symbol followed by a space and preceded by ONLY letters".
I tried to make the regex non greedy with the ?
symbol but clearly I am missing something and the result does not work as expected because it includes also me:
in the splitting operation.
It is essential I think to have a non greedy operator, because the string here is just an example I do not have always the word Mario
of course.
strsplit(x, "(?<=[[:alpha:]]):(?= )", perl = TRUE)
先感谢您!
我们可以用
Or with
str_split