get_tag_regex

Return RegEx body to liberally match an opening HTML tag.

Description

(string) get_tag_regex( (string) $tag ); 

Matches an opening HTML tag that: 1. Is self-closing or 2. Has no body but has a closing tag of the same name or 3. Contains a body and a closing tag of the same name

Note: this RegEx does not balance inner tags and does not attempt to produce valid HTML

Returns (string)

Tag RegEx.

Parameters (1)

0. $tag (string)
An HTML tag name. Example: video..

Usage

  1. if ( !function_exists( 'get_tag_regex' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // An HTML tag name. Example: 'video'. 
  5. $tag = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_tag_regex($tag); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function get_tag_regex( $tag ) { 
  2. if ( empty( $tag ) ) 
  3. return; 
  4. return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );