[Solved] Regex to find substring inside an html attribute [duplicate]


My warning in the comments section being said, you could use a combination of preg_replace_callback() and str_replace():

$str="<input data-content="This is a text string with a <br /> inside of it" />";
$regex = '/data-content="([^"]*)/i';
$str = preg_replace_callback($regex,
    function($matches) {
        return str_replace(array('<br/>', '<br />'), '', $matches[0]);
    },
    $str);
echo $str;
// output: <input data-content="This is a text string with a  inside of it" />

So what it does: matching everything in double quotes after data-content and replace it with variations of <br/>.
Once again, better use a parser or an xpath approach (look here on SO, there are plenty of good answers).

solved Regex to find substring inside an html attribute [duplicate]