Home > Back-end >  Remove characters after multiple points "..."
Remove characters after multiple points "..."

Time:10-05

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.

CodePudding user response:

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

CodePudding user response:

You can use,

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

CodePudding user response:

Does this work:

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