I have user input where some tags are allowed inside square brackets. I already wrote a regex pattern to find and verify what's inside the brackets.
In the input field of the user input field ([), a backslash can be escaped, and a backslash can be escaped with another backslash (\). I need an external pattern to avoid an odd number of consecutive backslashes before opening.
At the moment, I have to deal with something like this:
(?<!\\)(?:\\\\)*\[(?<inside brackets>.*?)]
It works fine, but the problem is that this code still matches possible pairs of consecutive backslashes in front of the brackets (even they are hidden), and look-behind just checks to see if there is another backslash attached to the pairs (or directly to the opening - a bracket). I need to avoid them all inside the gaze group, if possible.
Example:
my [test] string is ok my \[test] string is wrong my \\[test] string is ok my \\\[test] string is wrong my \\\\[test] string is ok my \\\\\[test] string is wrong ... etc
I am working with PHP PCRE
php regex pcre lookbehind negative-lookbehind
Wh1t3h4ck5
source share