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

228
Vistas
Regex to select all spaces between a special enclosure

I am trying to write a regex for Javascript that can select all whitespaces in between AMPScript brackets, the syntax for the Lang is something like this

%%[


set @truth = 'this is amp'

IF @truth == 'this is amp' THEN
set @response = 'amp rocks'
ELSE
set @response = '️...'
ENDIF

]%%

So far, I am able to select all the characters inside the given brackets using this expression:

%%\[(\s|.)*?\]%%

But this selects all the characters inside the enclosure, is there a method I can use to only select spaces/new lines/tabindents only?

Thanks in advance!

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

0

I believe this is what you want:

(?<=%%\[(\s|.)*)\s*(?=(\s|.)*\]%%)

https://regex101.com/r/EWhbuX/1

Edit

Here's a breakdown of the regular expression:

1.

First we start with a Positive Lookbehind (?<= )

This will make sure that the pattern that's following this, will be preceded by the pattern inside, but will not be include it in the matches.

In this case we want our matching pattern to be preceded by %%[ and any other character %%\[(\s|.)*

So, our resulting code for the Positive Lookbehind is

(?<=%%\[(\s|.)*)

2.

Next comes the pattern that we actually want to match after our Lookabehind, and (spoiler alert), before a Lookahead that we'll define later.

In this case, that's just any whitespace character, so our pattern will be

\s

(Yes, I just noticed that we don't even need the * in my original answer)

3.

Similarly to what we did at the beginning of the expression with the Lookbehind, we now need a Positive Lookahead (?= )

This is to make sure that our whitespaces will be followed by any character and ]%% (\s|.)*\]%%.

So this is our resulting Lookahead:

(?=(\s|.)*\]%%)

4.

Put everything together and you have your regular expression!

(?<=%%\[(\s|.)*)\s(?=(\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