Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
Regex match to check US State Code exist in string

I am large set of array from which I am trying to find the address

For example this(State Code :- CO)

0 Site Address, San Luis, CO 81152

Now to match this I am using this regex expression :-

e.match(/, CO \d/)

How can I incorporate many statecode in it like if I have to check for this(State Code :- NM)

2 X Valley Rd X P2, Questa, NM 87556

Any address state code can come, so I want it to dynamic to check all the state codes

Please suggest

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The most basic way to capture any state code would be to include a capture group with all the values you need to match.

Ex:

e.match(/, (CO|NM|TN|MO) \d/)

Wrap the different state options in parentheses, and use the pipe symbol to indicate "or".

If you have all the state codes in an array you could dynamically create this capture group.

ex:

const states = [
  "TN",
  "NM",
  "CO",
]

const regexStr = states.join("|")
const stateMatch = new RegExp(`, (${regexStr}) \d`)

e.match(stateMatch)
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try with the following regex:

, [A-Z]{2} \d{5}

It checks for symbols in the following succession:

  • , : a comma + a space
  • [A-Z]{2}: two letters
  • : a space
  • \d{5}: five digits

This approach will generalize on the state codes.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda