Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!