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

215
Vistas
Regex - Allow one or two alphabet and its can be at anywhere in string

I want regex which can fulfill below requirement:

  1. Between 6 and 10 total characters
  2. At least 1 but not more than 2 of the characters need to be alpha
  3. The alpha characters can be anywhere in the string

We have tried this but not working as expected : (^[A-Z]{1,2}[0-9]{5,8}$)|(^[A-Z]{1}[0-9]{4,8}[A-Z]{1}$)|(^[0-9]{4,8}[A-Z]{1,2}$)|([^A-Z]{3}[0-9]{6,9})

Can anyone please help me to figure it out?

Thanks

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

0

You can assert the length of the string to be 6-10 char.

Then match at least a single char [A-Z] between optional digits, and optionally match a second char [A-Z] between optional digits.

^(?=[A-Z\d]{6,10}$)\d*[A-Z](?:\d*[A-Z])?\d*$
  • ^ Start of string
  • (?=[A-Z\d]{6,10}$) Positive lookahead to assert 6-10 occurrences of A-Z or a digit
  • \d*[A-Z] Match optional digits and then match the first [A-Z]
  • (?:\d*[A-Z])? Optionally match optional digits and the second [A-Z]
  • \d* Match optional digits
  • $ End of string

See a regex demo.

about 4 years ago · Juan Pablo Isaza Denunciar

0

One option is to use the following regular expression:

^(?=.*[a-z])(?!(?:.*[a-z]){3})[a-z\d]{6,10}$

with the case-indifferent flag i set.

Demo

This expression reads, "Match the beginning of the string, assert the string contains at least one letter, assert the string does not contain three letters and assert the string contains 6-10 characters, all being letters or numbers".

The various parts of the expression have the following functions.

^              # match the beginning of the string
(?=            # begin a positive lookahead
  .*[a-z]      # match zero or more characters and then a letter
)              # end positive lookahead
(?!            # begin a negative lookahead
  (?:          # begin a non-capture group
    .*[a-z]    # match zero or more characters and then a letter
  ){3}         # end non-capture group and execute it 3 times
)              # end negative lookahead
[a-z\d]{6,10}  # match 6-10 letters or digits
$              # match end of string

Note that neither of the lookaheads advances the string pointer maintained by the regex engine from the beginning of the string.

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