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

139
Vistas
Using RegExp to test words for letter count

I've been trying to use RegExp in JS to test a string for a certain count of a substrings. I would like a purely RegExp approach so I can combine it with my other search criteria, but have not had any luck.

As a simple example I would like to test a word if it has exactly 2-3 as.

case test string expected result
1 cat false
2 shazam true
3 abracadabra false

Most of my guesses at regex fail case 3. Example: ^(?<!.*a.*)((.*a.*){2,3})(?!.*a.*)$

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

0

Could use this regex.

With any other character, including whitespace.

^[^a]*(?:a[^a]*){2,3}$

or if using multi-lines and don't want to span.

^[^a\r\n]*(?:a[^a\r\n]*){2,3}$

^                  # Begin 
[^a]*              # optional not-a
(?:                # Grp
  a                  # single a
  [^a]*              # optional not-a
){2,3}             # Get 2 or 3 a only
$                  # End

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

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