[R] Regex Split?

Leonard Mada
Thu, 04 May 2023 20:59:33 -0000

Dear R-Users,

I tried the following 3 Regex expressions in R 4.3:
strsplit("a bc,def, adef ,,gh", " |(?=,)|(?<=,)(?![ ])",
perl=T)
# "a"??? "bc"?? ","??? "def"?
","??? ""???? "adef" ","???
"," "gh"

strsplit("a bc,def, adef ,,gh", " |(?<! )(?=,)|(?<=,)(?![
])", perl=T)
# "a"??? "bc"?? ","??? "def"?
","??? ""???? "adef" ","???
"," "gh"

strsplit("a bc,def, adef ,,gh", " |(?<! )(?=,)|(?<=,)(?=[^
])", perl=T)
# "a"??? "bc"?? ","??? "def"?
","??? ""???? "adef" ","???
"," "gh"


Is this correct?


I feel that:
- none should return (after "def"): ",", "";
- the first one could also return "", "," (but probably not;
not fully
sure about this);


Sincerely,


Leonard