Say I have a vector containing some characters that I want to split based on a regular expression.
To be more precise, I want to split the strings based on a comma, followed by a space, and then by a capital letter (to my understanding, the regex
command looks like this: /(, [A-Z])/g
(which works fine when I try it here)).
When I try to achieve this in r
, the regex
doesn't seem to work, for example:
x <- c("Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), Loans, Long-term original maturity (over 1 year or no stated maturity)",
"Non financial corporations, Financial corporations other than MFIs, insurance corporations, pension funds and non-MMF investment funds, Assets (Net Acquisition of), Loans, Short-term original maturity (up to 1 year)")
strsplit(x, "/(, [A-Z])/g")
[[1]]
[1] "Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), Loans, Long-term original maturity (over 1 year or no stated maturity)"
[[2]]
[1] "Non financial corporations, Financial corporations other than MFIs, insurance corporations, pension funds and non-MMF investment funds, Assets (Net Acquisition of), Loans, Short-term original maturity (up to 1 year)"
It finds no split. What am I doing wrong here?
Any help is greatly appreciated!