Skip to content

Instantly share code, notes, and snippets.

@thenbrent
Created January 27, 2012 00:35
Show Gist options
  • Save thenbrent/1686151 to your computer and use it in GitHub Desktop.
Save thenbrent/1686151 to your computer and use it in GitHub Desktop.
Regex to match a given term only when it does not appear within certain HTML tags (ie. a) or WP shortcodes
$pattern = '/([^a-zA-Z0-9-_>\[])(' . preg_quote( $given_term ) . ')([^a-zA-Z0-9-_<\]])(?!([^<]*)(\>|\<\/a|\]|<\/h\d\>))/i'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment