It’s not possible to validate XML with regular expressions. XML is not a regular language.
Use an XML parser to try to parse the string as XML or else validate the XML document against a schema, for example a DTD or XSD file.
solved regular expression to check if string is valid XML [closed]