Skip to content

Instantly share code, notes, and snippets.

@rmdort
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save rmdort/10022895 to your computer and use it in GitHub Desktop.

Select an option

Save rmdort/10022895 to your computer and use it in GitHub Desktop.
Regex Pick shortcode from html
$pattern = '/(?(?=<\S*>)<\S*>|)\s*(\[[a-z|A-Z|-|\/|\s|\"|\=]*\])\s*(?(?=<\/\S*>)<\/\S*>|)/';
$html = '<p>
[highlight type="note"]You and your confinement nanny are bound by the basic Work Permit conditions. For example, the nanny cannot work for other employers in an occupation other than that stated in the Work Permit.[/highlight]</p>';
$filtered = preg_replace($pattern, '$1', $html);
// Returns
/*
[highlight type="note"]You and your confinement nanny are bound by the basic Work Permit conditions. For example, the nanny cannot work for other employers in an occupation other than that stated in the Work Permit.[/highlight]
Now use WP shortcode parser to process it
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment