Skip to content
Prev 366176 / 398502 Next

Regex to stop at first capital letter after sequence

All this assumes you are passing a character vector to sub. The combination of your subject line and the example are a bit underspecified. Here's two solution one of which is delivering everything beginning with the last cap after the (last) dash and the other is delivering everything after but not including the last <dash><spc> sequence:
[1] "Vasito"               "Cuentos"             
[3] "Promo vasito"         "Promoci?n escolar"   
[5] "Saluda a tu pediatra" "Pediatra"       

Greedy matching above, ungreedy; set by '(?U)' below:
[1] "Promo Vasito"         "Cuentos"             
[3] "Promo vasito"         "Promoci?n escolar"   
[5] "Saluda a tu pediatra" "Dia del Pediatra"
[1] "Promo Vasito"         "Cuentos"             
[3] "Promo vasito"         "Promoci?n escolar"   
[5] "Saluda a tu pediatra" "Dia del Pediatra"
David Winsemius
Alameda, CA, USA