I need to extract a particular value from this html snippet. As i would not like to use any external libraries the only way to achieve this using core java is using regular expressions. As i have never used regular expressions it would be great if you could suggest how the integer value could be retrieved from the below input.


I need to extract the integer value assigned to to GLOBALID.

2 Years
Discussion Span
Last Post by JamesCherrill

I'm not a Java programmer but any pythonista would answer to use the beautifulsoup library. From what I read here and there, the java equivalent is named JSoup. I think you could try this library.


JSoup looks like an excellent solution, except for OP's "i would not like to use any external libraries". Personally I find nothing wrong with external libraries, provided they are open source and I can bundle their classes into my own distribution jar.


On the other hand you clould just hack it...

If there's just one <tr><td>GLOBALID= prefix in the text, and the </td>suffix is on the same line then you can simply use String's indexOf to find the prefix's position, then indexOf again to find the first suffix after that position, which will give you the two indexes that you need to substring the actual value.
Depending on the file you may first have to deal with distracting white space anywhere in that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.