php - Regex to allow all characters except repeats of a particular given character -
i've been fumbling bit , thought i'd put regex experts:
i want match strings this:
abc[abcde]fff abcffasd
so want allow single brackets (e.g. [
or ]
). however, don't want allow double brackets in sequence (e.g. [[
or ]]
).
this means string shouldn't pass regex:
abc[abcde]fff[[gg]]
my best guess far based on an example found, like:
(?>[a-za-z\[\]']+)(?!\[\[)
however, doesn't work (it matches when double brackets present), presumably because brackets contained in first part well.
you want like:
^(?:\[?[^\[]|\[$)*$
at each character, pattern accepts opening bracket followed character, or end of string.
or little more neatly, using negative lookahead:
^(?:(?!\[\[).)*$
here, pattern match characters long doesn't see 2 [[
ahead.
Comments
Post a Comment