snowneji snowneji - 1 year ago 74
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!

Answer Source

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

# [1] "finance.lottery"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download