[R] Regex to stop at first capital letter after sequence
Bert Gunter
bgunter.4567 at gmail.com
Mon Dec 19 23:03:19 CET 2016
You don't need a regex.
?strsplit
Something like:
> y <-c("PPA 06 - Promo Vasito", "PPA 05 - Cuentos")
> sapply(strsplit(y, "-"),"[",2)
[1] " Promo Vasito" " Cuentos"
You may have to add spaces around your "-" , as you failed to supply
data so I cannot be sure what you have.
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Dec 19, 2016 at 1:25 PM, Omar André Gonzáles Díaz
<oma.gonzales at gmail.com> wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list