[R] Regex to stop at first capital letter after sequence

Omar André Gonzáles Díaz oma.gonzales at gmail.com
Mon Dec 19 22:25:07 CET 2016


I have the following strings:

[1] "PPA 06 - Promo Vasito"      [2] "PPA 05 - Cuentos"
[3] "PPA 04 - Promo vasito"      [4] "PPA 03 - Promoción escolar"
[5] "PPA - Saluda a tu pediatra" [6] "PPL - Dia del Pediatra"

*Desired result*:

[1] "Promo Vasito"                 "Cuentos"                "Promo vasito"

[4] "Promoción escolar"      "Saluda a tu pediatra"   "Dia del Pediatra"


*First attemp*:

After this line:

mead_nov$`Nombre del anuncio` <- gsub("(PPA.*)([A-Z].*)", "\\2",
mead_nov$`Nombre del anuncio`)

I get these:

[1] "Vasito"                 [2] "Cuentos"                [3] "Promo
vasito"
[4] "Promoción escolar"      [5] "Saluda a tu pediatra"   [6] "PPL - Dia
del Pediatra"


*Second attemp:*

mead_nov$`Nombre del anuncio` <- gsub("(PPA|PPL.*)([A-Z].*)", "\\2",
mead_nov$`Nombre del anuncio`)

I get this:

[1] "PPA 06 - Promo Vasito"     [2] "PPA 05 - Cuentos"
[3] "PPA 04 - Promo vasito"      [3] "PPA 03 - Promoción escolar"
[5] "PPA - Saluda a tu pediatra" [6] "Pediatra"


Thank you for your help.

	[[alternative HTML version deleted]]



More information about the R-help mailing list