I know that a lot of people have posted a similar question but with the g
flag, none of the "hacks" seem to work for me properly (meaning they don't work most of the time). Yes I want the g
flag The regex I've made is:
\~\![A-Za-z]+\ start(?:(?:(?:\(|,)\ ?[\w]+)*?\))\:\{([\S\s]+?)(?:(?<!\\)\}\:end)
This works fine when negative look-behind is supported. But when I do it in JavaScript. It doesn't support negative look behind. Here's the part where the problem lies:
(?:(?<!\\)\}\:end)
\}:end <- Not this
}:end <- This
foo}:end <- This
I've tried:
Try this, see the demo:
https://regex101.com/r/uE3cC4/17
Instead using lookbehind you can use lookahead
e.g.
to get
using lookbehind approach you can do
see: DEMO (lookbehind approach)
which here prevent a duplication of
#}
by using negative lookbehind.On the other hand, lookahead approach is also possible by "spawning lookahead",
let's consider our example text
become
here
%
s represent to lookahead.How we can spawn lookahead like that?
Let's consider lookahead approach regex for our example text
see: DEMO (lookahead approach)
A trick here is spawning lookahead together with
.
where the regex((?:(?!#}).)*)
can be expanded tothat means it will check for every letters to guarantee you that there is no
#}
in(.*)
.Thus, if apply this strategy to your regex you will get
see: DEMO