[R] Regex Split?

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Thu May 4 22:59:33 CEST 2023


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



More information about the R-help mailing list