Last active
May 7, 2019 14:39
-
-
Save gomesfellipe/e9780ec5bb0c51bb67e5e05cec97c71f to your computer and use it in GitHub Desktop.
Exemplo simples de como detectar e extrair determinada string utilizando o pacote `stringr` (Jeito nutella)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringr) | |
# Neste exemplo vamos obter tudo que venha apos | |
# a string "&token=": | |
# Link de exemplo: | |
link <- "http://www.google.com/aclk?sa=l&ai=DChcSEwi2vazh_ujhAhWHDJEKHcJaBWYYABAAGgJjZQ&token=AOD64_2roKLol2MibXGLfO6uavtAm10Hhw&ved=0ahUKEwiN26fh_ujhAhV7GLkGHUZSD6cQ0QwIFA&adurl=" | |
# Primeiro vamos localizar a posicao | |
# inicial da string desejada | |
posicao_inicial <- str_locate(link ,"&token=")[,"start"] | |
# Obter tudo que venha apos a posicao detectada: | |
link %>% str_sub(posicao_inicial) %>% str_remove("&token=") | |
# TODO: Transformar em uma funcao | |
# Fazer o mesmo usando regex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment