3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_shortcode_regex( $tagnames = null ) { global $shortcode_tags; if ( empty( $tagnames ) ) { $tagnames = array_keys( $shortcode_tags ); } $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() // Also, see shortcode_unautop() and shortcode.js. return '\\[' // Opening bracket . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] . "($tagregexp)" // 2: Shortcode name . '(?![\\w-])' // Not followed by word character or hyphen . '(' // 3: Unroll the loop: Inside the opening shortcode tag . '[^\\]\\/]*' // Not a closing bracket or forward slash . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket . '[^\\]\\/]*' // Not a closing bracket or forward slash . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ... . '\\]' // ... and closing bracket . '|' . '\\]' // Closing bracket . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags . '[^\\[]*+' // Not an opening bracket . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag . '[^\\[]*+' // Not an opening bracket . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag . ')?' . ')' . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] } $regex = get_shortcode_regex( ['audio'] ); preg_match_all("/$regex/", '[audio:http://localhost:8888/lusa/audio/1310seg02.mp3]', $m); preg_match_all("/$regex/", '[audio src="http://localhost:8888/lusa/audio/1310seg02.mp3"]', $m1); var_dump($m); var_dump($m1);
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(7) { [0]=> array(1) { [0]=> string(54) "[audio:http://localhost:8888/lusa/audio/1310seg02.mp3]" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(5) "audio" } [3]=> array(1) { [0]=> string(47) ":http://localhost:8888/lusa/audio/1310seg02.mp3" } [4]=> array(1) { [0]=> string(0) "" } [5]=> array(1) { [0]=> string(0) "" } [6]=> array(1) { [0]=> string(0) "" } } array(7) { [0]=> array(1) { [0]=> string(60) "[audio src="http://localhost:8888/lusa/audio/1310seg02.mp3"]" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(5) "audio" } [3]=> array(1) { [0]=> string(53) " src="http://localhost:8888/lusa/audio/1310seg02.mp3"" } [4]=> array(1) { [0]=> string(0) "" } [5]=> array(1) { [0]=> string(0) "" } [6]=> array(1) { [0]=> string(0) "" } }

preferences:
218.77 ms | 406 KiB | 326 Q