Situation
I have a string that should start and end with %% and must not contain consecutive % signs.
My input strings are the followings: the first one is invalid, and the second is valid.
%%askdj%%kl%%
%%askdj%kasd% lasdkl%%
I tried to validate with ^(%{2})([^\1]*?)\1$ and with ^(%{2})(.*(?!\1).*)\1$ but for the both cases I got the same result (it matches %%askdj%%kl%% as well, but should not).
I expected to exclude the first captured group by [^\1], but it did not work. Then I tried with negative lookahead, but it still did not work.
Questions
- How do I match the valid text between
%%? - How would you explain the not working behavior of the
[^\1]pattern?