I am trying to get a regular expression pattern to implement a shortcode feature in Joomla CMS, using plugins, similar to WordPress.
The shortcode may be a self closing one like {myshortcode shortcode="codeone"} at some occassions and may be an enclosed ones like:
{myshortcode shortcode="anothercode"|param="test"}
{column}column 1{/column}
{/myshortcode}
I managed to figure out the regular expression used in WordPress:
{(}?)(myshortcode)(?![\w-])([^}\/]*(?:\/(?!})[^}\/]*)*?)(?:(\/)}|}(?:([^{]*+(?:{(?!\/\2})[^{]*+)*+){\/\2})?)(}?)
This is working fine if the content contains one or more self closing shortcodes, or one or more of the enclosed shortcodes. But if the content contains a mixture of both, it won't work.
Instead of using the square brackets [], I am using the curly braces {}, as this is how content plugins are used in Joomla.
Now please check the below HTML snippet:
<div id="lipsum">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin pellentesque lectus tellus, ut tincidunt orci posuere non. Aliquam erat volutpat. Phasellus in lobortis dolor, porta varius nunc. Ut et felis rutrum, pharetra mi a, ullamcorper purus. In vitae fringilla velit. In nec scelerisque mauris, sed eleifend urna. Duis feugiat risus et arcu eleifend venenatis.
</p>
<h3>Shortcode 1</h3>
<p>{myshortcode shortcode="codeone"}</p>
<h3>Shortcode 2 - </h3>
<p>{myshortcode shortcode="anotherone"|param="test"}
{column}column 1{/column}
{/myshortcode}
</p>
<p>
Duis quis nisl fringilla, porttitor tellus a, congue mauris. Sed posuere erat vel metus egestas, eget lobortis dolor pretium. Proin iaculis pharetra consectetur. Sed in enim ultricies, sagittis nisl vitae, porttitor libero. Praesent ut erat nisi. Maecenas luctus magna lacus. Mauris ullamcorper maximus arcu et tincidunt. Aenean cursus enim blandit, scelerisque ex sed, vestibulum felis. In magna massa, sagittis in eleifend vel, tristique vitae nisi.
</p>
</div>
Here the HTML contains both self enclosing and enclosing shortcodes. In this case the above regular expression pattern is not working, as it matches the two shortcodes as one, starting from {myshortcode shortcode="codeone"} to {/myshortcode} as a single shortcode.
So my question is is there a pattern I can use to match both the shortcodes?
Please check the current state of it here http://regex101.com/r/tF0mA9/1. Here I am expecting two matches.
Thank you for your help.