0

I'm trying to strip a tag from a document to help my XML parser parse it, but my Regex isn't working. Here's what I have:

stripHead = new RegExp('<HEAD[\s\S]*?\/HEAD>')
doc = doc.replace(stripHead, '')

The relevant part of the doc:

<SAMI>
<HEAD>
<TITLE>TEST_Eclipse_SMI</TITLE>
<SAMIParam>
      Media {TEST_Eclipse_SMI.wav}
  Metrics {time:ms;}
  Spec {MSFT:1.0;}
</SAMIParam>    <STYLE TYPE="text/css">
<!--
     P { font-family: Arial; font-weight: normal; color: white; background-color: black; text-align: center; }
     .ENUSCC { name: English; lang: en-US ; SAMIType: CC ; }
-->
</STYLE>
    </HEAD>
<BODY>

Regex101 seems to think this matches fine, but it's not replacing anything.

Joren
  • 9,623
  • 19
  • 63
  • 104
  • Regular expressions generally only match a single line at a time. Your example shows multiple lines that you want to match between, so I don't think that's going to work. – Herms Aug 17 '16 at 18:56
  • 2
    Either `stripHead = new RegExp('')` or `stripHead = //` – Wiktor Stribiżew Aug 17 '16 at 18:56
  • In JS I don't think there is any difference between double and single quoting except that you have to escape the delimiter inside the quote. Except for that, everything is either un-escaped or if it's a special form like `\t` or `\n` it inserts the control code. So your regex string would be `''` –  Aug 17 '16 at 19:23
  • Escaping the backslashes fixed it. You should submit that as an answer. – Joren Aug 17 '16 at 20:14

0 Answers0