snowneji snowneji - 10 months ago 51
R Question

R: how to use regex to substitute an element appeared multiple time by single one of them

I have:

txt= 'finance . . . . . lottery ticket . . . community'

trying to get:

txt2 = 'finance.lottery'

but the following didn't work:


Did I do anything wrong here? Thanks!


There are spaces between . in your text, you need to include that in your regex as well:

# [1] "finance.lottery"