Tuesday, January 31, 2012

Regular Expression (RegEx) Remove illegal ones

Yesterday I was working on a site which pulled data from a third party xml file. We were having problems with illegal characters and as we have no control over what was being entered we decided to handle it on our end. Just thought I would post up a handy RegEx which cleaned it up for us.

cleanXML = reReplaceNoCase(xml, "[^-a-zA-Z0-9@`!""##$%&'()*+,-./:;\[{<\|=\]}>^~?_ ]", "", "ALL");