Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda