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

174
Vistas
Testing for exact string with Regexp

I'm trying to find the exact match for the following strings;

/test/anyAlphaNumericId123
/test/anyAlphaNumericId123/

That will not match the following

/test/anyAlphaNumericId123/x

I have the following Regex currently, which matches both former cases and not the latter;

/(\/test\/)(.*?)(\/|$)/

But on attempting to call str.match on it, I will also get a result for the latter, as it has a partial match. Can I accomplish this with Regex alone?

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

0

You can write the pattern as:

^\/test\/[a-zA-Z0-9]+\/?$

The pattern matches:

  • ^ Start of string
  • \/test\/ Match /test/
  • [a-zA-Z0-9]+ Match 1+ times any of the allowed ranges
  • \/? Match an optional /
  • $ End of string

Regex demo

Example using a case insensitive match with the /i flag:

const regex = /^\/test\/[a-z0-9]+\/?$/i;
[
  "/test/anyAlphaNumericId123",
  "/test/anyAlphaNumericId123/",
  "/test/anyAlphaNumericId123/x"
].forEach(s =>
  console.log(regex.test(s) ? `Match: ${s}` : `No match ${s}`)
);

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