Chris
Chris

Reputation: 166

Remove characters after multiple points "..."

I have strings like these:

text <- c("11. Availability...17", "1. Turnover...7")

I want:

c("11. Availability", "1. Turnover")

My idea is to remove everything behind/including the "..." . Unfotunately I'm not able to fix it with gsub() or similar.

Upvotes: 0

Views: 48

Answers (3)

Chris
Chris

Reputation: 2286

Also

gsub('\\.{2}.*', '', text)
[1] "11. Availability" "1. Turnover" 
# or
 gsub('\\.{2,3}.*', '', text)
[1] "11. Availability" "1. Turnover"
#where 3 has no impact on this, but useful for further cases

Upvotes: 1

Karthik S
Karthik S

Reputation: 11584

Does this work:

gsub('\\.{2,}\\d+$', '', c("11. Availability...17", "1. Turnover...7"))
[1] "11. Availability" "1. Turnover"   

Upvotes: 0

Sotos
Sotos

Reputation: 51592

You can use,

gsub('\\.\\.\\..*', '', text)
#[1] "11. Availability" "1. Turnover"

Upvotes: 0

Related Questions