I have this regex (Regex101):
\[tag(?:=(["']?)(.+)\1)?\](.*?)\[\/tag\]
It allows four different forms:
[tag=foo]foo[/tag]
[tag="foo"]foo[/tag]
[tag='foo']foo[/tag]
[tag]sdfo[/tag]
All forms works, but if I try to add another [/tag]
at the end of each form, the first one will continue the catch until the last closing tag (as shown in the linked page). Is it possible to make it not continue the catch, keeping all the forms still valid?
Also, any other suggestion to catch any other strange behavior are accepted.
Just make the .+
non-greedy and it should all work.
\[tag(?:=(["']?)(.+?)\1)?\](.*?)\[\/tag\]