Find a number after a specific word with grepl and regex {r}

1

Hello, I have a list of addresses and I am trying to check which ones have numbering and which ones do not. However, I have some strings that end with number and I'm trying to create a regex to filter those results. I do not want you to return numbers that come after the words "street" and "km."

> #exemplo:
> enderecos <- c("rua 5", "rua x, casa y", "km 18")
>
> #resultado esperado:
> FALSE TRUE FALSE

Thank you for helping me.

    
asked by anonymous 02.08.2018 / 22:23

2 answers

1

You can use the following regular expression pattern

(?:km|rua)\s\d{1,9}

I tested with the data reported and others also, seems to be sufficient. Follow the test link

    
02.08.2018 / 22:52
1

The following regular expression should solve the problem:

"(?:km|rua)+\s*\D+?"

Despite the small amount of data, I believe that if there are more variations, just edit them.

Example in Regex101

    
02.08.2018 / 22:42