1

What would be the regex to remove a variable string like the following in the html?

<% include Banner %>

Here's what I've tried so far:

$('body').html().replace('<%(.*?)%>','');
3
  • Are you sure that actually exists as of the time you're trying to operate on it? Because frankly, I doubt it. Commented Nov 10, 2013 at 22:42
  • Looks a lot like EJS or some other serverside templating system ? Commented Nov 10, 2013 at 22:56
  • Silverstripe template system. I'm using jQuery .load to display pre-generated .ss template includes based on a customised online order to speed up dev and html/css cut Commented Nov 10, 2013 at 22:59

1 Answer 1

1

You might want to set your html, turn your regex into a regex and change your < to &lt;

var $body = $('body');
$body.html($body.html().replace(/&lt;%(.*?)%&gt;/,''));

Demo: http://jsfiddle.net/7nWyA/

If jQuery finds < and > when it's not actually a html tag it will replace it with &lt; and &gt;

Sign up to request clarification or add additional context in comments.

1 Comment

+1 and turn your regex into a regex The sentence of the day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.