regex - Add space between two letters in a string in R -
regex - Add space between two letters in a string in R -
suppose have string like
s = "pleaseaddspacesbetweenthesewords" how utilize gsub in r add together space between words get
"please add together spaces between these words" i should like
gsub("[a-z][a-z]", ???, s) what set ???. also, find regular look documentation r confusing reference or writeup on regular expressions in r much appreciated.
you need capture matches utilize \1 syntax refer captured matches. example
s = "pleaseaddspacesbetweenthesewords" gsub("([a-z])([a-z])", "\\1 \\2", s) # [1] "please add together spaces between these words" of course, puts space between each lower-case/upper-case letter pairings. doesn't know real "word" is.
regex r gsub
Comments
Post a Comment