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

183
Visualizações
regex expression in js

i want to ask how should i modify this expression /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/ so that the evaluated value always start with +266 and 2 digits after that should be 22 or 28 or 57 or 58 or 59 or 27 or 52 followed by 6 random numbers

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

0

It looks like you're almost good to go, except it's not clear why the first ? is in there if you always want to start with +266, also you wrote 37 in the question but have 27 in the regex you included.

Also you didn't say anything about needing capturing groups so you can do away with the first set of brackets. The second set of brackets is required for the 'or' (|) but you can include ?: to make it non-capturing.

Give this a try:

/^\+266(?:22|28|57|58|59|27|52)\d{6}$/gm

You can see it working here:

https://regex101.com/r/ZQqthS/1

about 4 years ago · Juan Pablo Isaza Relatório

0

Your original regex should basically work. I was about to write the same comments as @Ljdyer, but as he already mentioned it I can save my breath.

In my regexp I used a few character classes, like [28], to shorten it, but that is optional.

const rx=/^\+266(?:2[28]|5[2789]|37)\d{6}$/;

console.log(["+26628123456","+26657763883",
 "+26638123456","+266591234567"]
.map(s=>s.match(rx)));
// the first two will match, the others won't

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