I’m running into an issue with the following.
I need to clean up HTML before rendering it to the browser.
The current regex matches everthing like “{varname}” no problems so far, however I need to exclude matches which are found within script tags.
*Example was a bit unclear, so updated *
Example:
<html>
<head></head>
<body>
this is an example `{var}` variable, <- this should be matched/removed
<script>
// don't match below arguments in other words don't let regex remove them/match them
myMethod("{param1:'foo', param2:'bar'}");
</script>
</body>
</html>
Make it specific and just match alphanumeric characters:
Would avoid the
{x: 'y'}example problem already.To exclude document parts with preg, use
preg_replace_callback; list the undesired(<script>.+?</script>)|...as first alternative, then switch-handle in the callback.