Search code examples
javascriptregexstringreplacexmldocument

Replace XML initial tag with regex in JS


I want to get all the strings starting with <?XML and ending with ?> to replace in Javascript strings.

For example <?XML version="1.0" encoding="UTF-8" ?> should be replaced with ''

because parsing it is resulting in an error.


Solution

  • regex that starts with <?XML and ends with ?> should be given as

    <\?\s*XML.*\?>