Regex to remove xml declaration from a string

You probably want either this: <\?xml.*\?> or this: <\?xml.*?\?>, because the way you have it now, the regex is not looking for '?>' but just for '>'. I don't think you want the first option, because it's greedy and it will remove everything between the first occurrence of ''. The second option will work as long as you don't have nested XML-tags. If you do, it will remove everything between the first ''. If you have another '' tag.

Also, I don't know how regexes are implemented in .NET, but I seriously doubt if they're faster than using indexOf.

Tags:

C#

Xml

Regex

Tidy