0

I'm not good at all in regex and I'm looking for an expression to get everything between and including either:

<script*/> OR 
<script*</script> //asterisk refers to everything between

Basically, I want to copy sections from a single element for print but delete all tags and everything in between

A single statement that covers both scenarios would be preferable, but two solutions will work just fine

Any help will be greatly appreciated

  • 3
    If you're looking to parse some sort of HTML or XML, a parser dedicated for that is probably a better way to go than regexes – Ryan J Jan 15 '15 at 21:50
  • 2
    Also, if you're trying to prevent XSS, Basic Regex rarely covers enough to deter any but the most inexperienced attackers. There are a myriad of other attack vectors, including `onLoad` attributes, malformed tags, and more. Please read my answer to this question: [Disable javascript entry into form](http://stackoverflow.com/questions/27576598/disable-javascript-entry-into-form/27576683#27576683) – Brandon Anzaldi Jan 15 '15 at 21:53

1 Answers1

0

This should work for both cases:

<script.*((/>)|(</script>))
VladL
  • 12,769
  • 10
  • 63
  • 83
  • I've tested it, post your sample string which you are trying to parse – VladL Jan 16 '15 at 10:09
  • Depending on programming language you can set an option for interpreting . as new line symbol as well. In c# its "RegexOptions.SingleLine" – VladL Jan 17 '15 at 22:40