Created
January 29, 2016 16:45
-
-
Save jonatasemidio/8898e8b4290cf059dff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGEX = "^[\\w\\s/<>?\".=-]*[áéíóúçàãõâêô:\\s]*\$" | |
nome = " jonatas#!@#%¨&* emidio" | |
texto = ''' | |
<?xml¨&*()¨&*( version="1.0" encoding="ISO-8859-1"?> | |
<SAIDA> | |
<HEADER> | |
<ERRO> | |
<CODIGO-ERRO>1454014207309</CODIGO-ERRO>%¨&*() | |
<ORIGEM-ERRO>The data "" is not legal for a JDOM character content 0x0 is not a legal XML character.</ORIGEM-ERRO> | |
</ERRO> | |
</HEADER> | |
</SAIDA> | |
''' | |
xmlvalido0 = texto.collect { linha -> linha.collect{ if(it.matches(REGEX)) it else '' }.join() }.join() | |
println xmlvalido0 | |
xmlvalido1 = texto.collect { linha -> | |
linha.collect{ | |
if(it.matches(REGEX)) | |
it | |
else | |
'' | |
}.join() | |
}.join() | |
println xmlvalido1 | |
StringBuilder xmlvalido2 = new StringBuilder(); | |
for (String linha in texto.split("\n")){ | |
String[] caracteres = linha.split(""); | |
StringBuilder linhaValida = new StringBuilder(); | |
for (int i = 0; i < caracteres.length; i++){ | |
if(caracteres[i].matches(REGEX)){ | |
linhaValida.append(caracteres[i]); | |
} | |
} | |
xmlvalido2.append(linhaValida + "\n"); | |
} | |
println xmlvalido2 | |
//def parseline(line){ | |
// sb = new StringBuffer() | |
// line.collect{ if(it.matches(REGEX)) { sb << it } } | |
// return sb.toString() | |
//} | |
//sb = new StringBuffer() | |
//nome.collect{ if(it.matches(REGEX)) { sb << it } } | |
//println sb.toString() | |
//println nome.collect{ if(it.matches(REGEX)) it else '' }.join() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment