One regex for tag with multiple parameters and replacement
[tag]foobar[/tag]
[tag parameter1]foobar[/tag]
[tag parameter2="whatever"]foobar[/tag]
[tag parameter1 parameter2="whatever"]foobar[/tag]
[tag parameter2="whatever" parameter1]foobar[/tag]
Can I match all these combinations in one expression? Ideally suitable for additional parameters. I tried a few things but nothing works. For now i am going to match every single combination but i guess, that's not the best.
The second matter, i want to make a replacement for the parameters.
parameter1
to class="tagclass"
parameter2="input"
to id="in开发者_运维知识库put"
Is it possible to do it all in one step?
Thanks and regards, Alex
WordPress has code that does that:
http://core.trac.wordpress.org/browser/trunk/wp-includes/shortcodes.php
It doesn't work 100%, but it gets the job done. See in particular the shortcode_parse_atts()
function (line 225 as I write, but subject to change in later versions of WP).
精彩评论