Last active
August 29, 2015 13:58
-
-
Save rmdort/10022895 to your computer and use it in GitHub Desktop.
Regex Pick shortcode from html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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