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");

1 comment:

  1. Thank you, I was getting illegal characters from users in some XML too and this code helped me out a lot because I didn't have to create it from scratch!

    ReplyDelete