Skip to content

Instantly share code, notes, and snippets.

@jakefolio
Created May 15, 2014 20:53
Show Gist options
  • Save jakefolio/3d7d9a890de268f22318 to your computer and use it in GitHub Desktop.
Save jakefolio/3d7d9a890de268f22318 to your computer and use it in GitHub Desktop.
REGEX to find all links with the class of "demo" that do not have a </i> preceding the </a>
<?php
$content = '<div class="actions">
<a href="http://davidwalsh.name/demo/folding-animation.php" class="demo">Some text<i class="something"></i></a>
<a href="http://davidwalsh.name/demo/folding-animation.php" class="demo">Some other text</a>
<div class="clear"></div>
</div>';
$results = preg_replace('/(<a\s+.*?class="demo".*?)((?<!<\/i>)<\/a>)/i', '${1}<i class="something"></i></a>', $content);
echo $results;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment