Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda