fork download
  1. x <- c("1.0% SELLING","3.2% AND 1.0% AND 1.2%","1.0% SOLD PRICE","1.2% PURCHASE PRICE FINAL","2.5% AND 1.0%","1.0% SELLING 2.0% people")
  2. sub('^(\\d+\\.\\d+%)(?:\\s+\\w+)*$', '\\1', x, perl=TRUE)
  3. library(stringr)
  4. stringr::str_replace(x, '^(\\d+\\.\\d+%)(?:\\s+\\w+)*$', '\\1')
  5.  
Success #stdin #stdout 0.29s 42632KB
stdin
Standard input is empty
stdout
[1] "1.0%"                     "3.2% AND 1.0% AND 1.2%"  
[3] "1.0%"                     "1.2%"                    
[5] "2.5% AND 1.0%"            "1.0% SELLING 2.0% people"
[1] "1.0%"                     "3.2% AND 1.0% AND 1.2%"  
[3] "1.0%"                     "1.2%"                    
[5] "2.5% AND 1.0%"            "1.0% SELLING 2.0% people"