Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a string in between two quote marks

Tags:

java

regex

How would I get a value in between two the quotes after value=?

So, value="hi my name is bob" />
would return: hi my name is bob
or value="Ouch! "that hurt" lol..." />
would return: Ouch! "that hurt" lol...

I know the value=" TEXT_HERE " /> will always occur and I want the string inside of it. and yes, there is always a space before the /> at the end. It is HTML code I am parsing, I have gotten everything except for this field to parse correctly.

EDIT Let me clarify a little bit. I can't really use any side tools because I am using Webdriver to parse the page, after I get the source I throw the HTML into a string and then I try to parse the "value" tag out of all that data.
So the regex code has to be able to maneuver through all kinds of coding and get whatever the value field is. And I need every value field's data.

like image 993
Austin Avatar asked Dec 06 '25 10:12

Austin


1 Answers

You could use String.indexOf() to search for the first occurrence of ". Save the first occurrence index, get the last occurrence index using String.lastIndexOf() and call String.substring() to get the substring you want out.

like image 129
Michael Fox Avatar answered Dec 08 '25 01:12

Michael Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!