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

133
Visualizações
have a regex match 'a-a' and 'b-b', but not 'a-b'?

this is a really hard question to phrase, but is there a way to have a regex match 'a-a' and 'b-b', but not 'a-b'? basically i want it to match with the same character either side of a middle character (such as '-') but that said character is interchangeable with other characters in a set of characters (such as [abc]). I'd like the solution to be not brute forced as the set of characters i have in mind is quite large, and the answer should be in javascript

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

0

The pattern you are looking for is /^([a-c])-\1$/

You may reference any captured group through a \number syntax, where number is the number of your group, starting from 1.

Tests:

const pattern = /^([a-c])-\1$/;

pattern.test('a-a'); // true
pattern.test('b-b'); // true
pattern.test('c-c'); // true
pattern.test('a-b'); // false
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