Skip to content
Prev 173739 / 398503 Next

gsub and regex to tidy comma-limited values

with the example below, i think the following solves your problem:

    text = ',,,apple,,orange,,,,,lemon,strawberry,,,,'
    gsub('^,+|,+(?=,)|,+$', '', text, perl=TRUE)

vQ
Tom wrote: