-2

I'm returning some data from a database that looks like this

<[<language><text xml:lang="">Automation1406741539346</text></language>]>

What would be the easiest and best way I can remove everything from this string except Automation1406741539346?

thebluephantom
  • 16,458
  • 8
  • 40
  • 83
Doctor Who
  • 1,287
  • 5
  • 25
  • 46
  • regex is probably the best way. look at this [link](http://stackoverflow.com/questions/335250/parsing-xml-with-regex-in-java) – jcjunction Jul 30 '14 at 17:43
  • 2
    `String s = "Automation1406741539346";` – Maroun Jul 30 '14 at 17:43
  • @jcjunction I like this quote from the page you link to: "Using regexes to parse XML always ends in tears." – Micah Smith Jul 30 '14 at 17:44
  • @MicahSmith nobody said it was fun. ha. I use C# usually which has great tools for XML parsing. – jcjunction Jul 30 '14 at 17:46
  • 1
    A quick google lead me to this: ["How to parse or read XML File in Java"](http://javarevisited.blogspot.mx/2011/12/parse-xml-file-in-java-example-tutorial.html) – Barranka Jul 30 '14 at 17:49

1 Answers1

1

Try this regex..

public static void main(String[] args) {
    String s= "<[<language><text xml:lang=\"\">Automation1406741539346</text></language>]>";
    Pattern p = Pattern.compile("<text.*?>(.*?)</text>");
    Matcher m = p.matcher(s);
    m.find();
    System.out.println(m.group(1));
}

O/P :

Automation1406741539346
TheLostMind
  • 35,966
  • 12
  • 68
  • 104