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

161
Vistas
Regular expression to match all words in and including a given word

I'm looking for a regular expression (using JavaScript) to match all 3-6 letter words that contain all or some subset of the letters in a given word. For example, if my word is "rescue", then I should match "use", "cure", "reuse", "secure", and so on. What I have right now is:

\b(?!\w*(\w)\w*\1)[rescue]{3,6}\b

...And this works, but for the repeat letters. It won't match words with 2 e's:

enter image description here

r, e, s, c, u, e, should match at most 1 r, s, c, and u, with at most 2 e's.

Here I'm stuck. I'm not great at these things and it's a wonder I've come this far. This is not an operation I need to perform quickly or frequently, and the word list in only 20,000 words or so. I'm not concerned with the most efficient solution. I would love some help. Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't need the negative lookahead, as how it is currently written, this part (?!\w*(\w)\w*\1) asserts that what is to the right is not a word char (\w) that can occur again with \w*\1

Instead you could assert the length first, and then match one of the characters r e s c u e

\b(?!\w*([rescue])\1)(?=\w{3,6}\b)\w*[rescue]\w*\b

See a regex 101 demo.

If the word can only consist of the listed characters:

 \b(?!\w*([rescue])\1)[rescue]{3,6}\b

See another regex 101 demo.

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