0

I'm trying to apply regex in my android code to get a specific value from a HTML page. The HTML code is :

    <html>
<head>
<title>Sometitle</title>
<body>
<span class="shout">VAL 32354</span>
</body>
</html>

my aim is to extract this text "VAL 32354" from the above mentioned HTML code ? I've searched long for regex with android and I found rare number of tutorials which were are all complicated for a beginner programmer like me . Any thoughts how to do that ? and thanks in advance

Note : if regex doesn't work in this case , what are the alternatives ?

AlphaCode
  • 439
  • 1
  • 3
  • 17
  • [You can't parse HTML with regex. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Have you tried using an XML parser instead?](http://stackoverflow.com/a/1732454/1229023) – raina77ow Dec 20 '14 at 21:14
  • @raina77ow Well I do remember doing something similar with Regex in VB.NET few years ago and it worked – AlphaCode Dec 20 '14 at 21:18
  • if it doesn't work with Android , what are the alternatives ? – AlphaCode Dec 20 '14 at 21:18
  • Tell me, have you actually read the linked answer? – raina77ow Dec 20 '14 at 21:18
  • Well I read most of it , he's saying regex can't work with HTML etc.. – AlphaCode Dec 20 '14 at 21:19
  • @raina77ow: Please don't just link to that question without adding another link to an actual HTML parser library. That question by itself is basically useless. – nhahtdh Dec 21 '14 at 13:08
  • Since when we should answer the questions by giving links? The answer is clear: stop using regex, find yourself an HTML parser. – raina77ow Dec 21 '14 at 13:10

1 Answers1

2

Why not use Jsoup to parse the HTML?

See http://www.survivingwithandroid.com/2014/04/parsing-html-in-android-with-jsoup.html

In this example, you could get the element with Elements shoutList = doc.select("#shout");

rymate1234
  • 448
  • 4
  • 16