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

124
Vistas
Is it possible to use only lookaround to match characters that are not repeated immediately before and after?

For example, to match the first slash after the domain name in the URL.
Intent: Only match '/' in '.com/...' but not any '/' in 'https://'.

url = 'https://example.com/...';
[
url.match(       /(?<!\/)(?<slash>\/)(?!\k<slash>).../), // [A]
url.match(/(?<!\k<slash>)(?<slash>\/)(?!\k<slash>).../)  // [B]
]

The above [A] returns the correct match, but [B] is the kind of expression I want (although it did not match any characters), that is, to use the / character only 1 time in the body of regex literals.

Is there a generalized form of expression similar to [B] (using capturing groups or the like) and using only regular expression literals (instead of using the constructor (RegExp))?

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

0

You can put a positive lookbehind after an optional character inside a negative lookahead. The lookbehind asserts 2 consecutive slashes (using a reference). This way the lookbehind tests the captured slash position and also the position before. Obviously, when it succeeds, the negative lookahead fails.

/(\/)(?!.?(?<=\1{2}))/

(feel free to use named captures)

or without captures:

/\/(?!.?(?<=\/\/))/
about 4 years ago · Juan Pablo Isaza Denunciar

0

If all your inputs are URLs, this will do what you want:

/\/\/.+?(\/)/

And then capture the first group:

url = 'https://example.com/...';
const matches = url.match(/\/\/.+?(\/)/);
console.log(matches[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