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

190
Vistas
How to convert a PCRE regex pattern with match reset for ECMAScript?

Suppose I have the following pattern:

|              |                 |      |      |         |
|            |           |      |      |         |
|              |     |      |      |         |

I am interested in a regex expression that can match anything between the second and third | characters, as shown below.

enter image description here

I can do this using the following pattern ^\|\s+\|\K\s+(?=\|) (regex demo here) with the PCRE flavor.

However, my requirement is to find a pattern supported by the ECMAScript flavor. The use of the match reset (i.e., \K) does not work in this case. Do you have any ideas on how to obtain something similar that works in ECMAScript?

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

0

As indicated in the comments this can be much easier solver by splitting the string on |.

// The string with 'a', 'b', and 'c' added for clarity.
const string = "|              |        a         |      |      |         |\n|            |     b      |      |      |         |\n|              |   c  |      |      |         |";

// Print the string.
console.log(string);

// Split and print the regions between the 2nd and 3rd `|`.
string.split('\n').forEach(line => {
    console.log(line.split('|', 3)[2])
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

While splitting is indeed easier, I still wanted to see if I could do it with regex. You can use lookahead to match the pattern from the beginning of the line, and within the lookahead, capture the contents of what you're looking for in a capture group.

Example: https://regex101.com/r/v0GnAN/1

(?=^\|[^|]*\|([^|]*?)\|)

This is a lookahead group that's looking for anything between two | characters, then matching the same but within a capture group. This is slightly different from the \K approach in that your results are now in group 1 instead of group 0.

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