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

309
Vistas
Find a string that contains 1 to 4 uppercase letters and 0 to 3 digits (visual studio code, javascript regex)

From lines in a file i would like to find those that

  • the lines starts with a year YYYY ^(202\d) for example 2022or 2023
  • followed by at least 1 and up to 4 uppercase letters ABCD [A-Z]{1,4} or up to 3 numbers \d{1,3} and at least one letter [A-Z]{1} for example ABCD or A123 or 1A23 or 123A
  • followed by either A or R

Examples

YYYYxxxxA   // find rows that match 2022xxxxA
2022A150A   // relevant matches
2022B260A   //     "
20223A70A   //     "
20224B84A   //     "
20224B  A   // not relevant due to spaces \s\s 
20221234A   // not relevant due to 4 digits and no letter

In visual-studio-code i tested javascript regex (see my demo@regex101.com)

These two regex seem to work

2022(\d\D\w\w|\D\d\w\w|\d\d\D\w|\d\d\w\D|\D\D\D\D)A
// or
^(202\d)(\d{0,3}[A-Z]{1,4}|[A-Z]{1,4}\d{1,3})([\dA-Z]{0,4})A

Explanation from regex101.com

  • at start of a line
  • 1st Capturing Group (202\d) matches 202 literally and \d matches a digit (equivalent to [0-9])
  • 2nd Capturing Group (\d{0,3}[A-Z]{1,4}|[A-Z]{1,4}\d{1,3})
  • 2 Group 1st Alternative \d matches a digit (equivalent to [0-9]){0,3} matches the previous token between 0 and 3 times
  • 2 Group 1st Alternative match a single character present in the list below [A-Z] {1,4} matches the previous token between 1 and 4 times
  • the other alternatives | are a variation of the first

Demo at regex101.com

Question

I would like to know if there is a better option than

^(202\d)(\d{0,3}[A-Z]{1,4}|[A-Z]{1,4}\d{1,3})([\dA-Z]{0,4})A

for (xxxx) should contain at least 1 uppercase and no more than 3 digits?

Test with my demo

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

0

Your final regex will also match the below two lines, because it allows up to 3+4+4 characters for that second part, and also just 1 letter:

2022999BBBB9999A
2022BA

For the part that must have 4 alphanumericals, including at least one letter, you could express that condition as follows:

  • match exactly four characters that are either digits or uppercase letters
  • require that one of those must be an uppercase letter, using look-ahead

Like this:

^(202\d)(?=.{0,3}[A-Z])([\dA-Z]{4})A

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