Regex to check a string

Asked

Viewed 87 times

0

I’m having trouble creating a regex, I’d like him to identify SP or sp or São paulo, then any other words and again check if you have, outro or Minas gerais(other states), in this sequence, example that I’ve assembled :

(sp|SP|sao paulo|são paulo|São paulo)+.*(outro|mg|MG|pr|PR|Acre|ac|AC|Alagoas|AL|al|Amapa|APap|Amazonas|AM|am|Bahia|BA|ba|Ceará|ce|CE|Distrito Federal|DF|df|Espírito Santo|es|ES|Goias|GO|go|Maranhão|MA|ma|Mato Grosso|MT|mt|Mato Grosso do Sul|MS|ms|Minas Gerais|MG|mg|Pará|PA|pa|Paraiba|PB|pb|Parana|PR|pr|Pernambuco|PE|pe|Piaui|PI|pi|Rio de Janeiro|RJ|rj|Rio Grande do Norte|RN|rn|Rio Grande do Sul|RS|rs|Rondônia|RO|ro|Roraima|RR|rr|Santa Catarina|SC|sc|Sergipe|SE|se|Tocantins|TO|to)+

but the .* ends up validating this, and it’s not what I want.

Test example

from Sao Paulo to another state
from sp to minas gerais
from São Paulo to mg

  • 3

    Try to change the .* for .*?

  • 2

    You can give input examples along with what you want to capture in each?

  • The first part house "spSPsao paulo", that’s right?

  • that check if he typed something related to sao paulo, so I put the variations, already put the . *? , but it does not work 100%

  • example input: de sao paulo to another state; de sp to minas gerais; de São Paulo to mg

  • 1

    Can you play on https://regex101.com/ these examples? Include the ones that aren’t working too.

  • I was testing it anyway, I made some adjustments and at first it’s working, thanks for the help

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.