Let's say we have a String in Java, which contains HTML code.
I would like to do something like return every substring within this string that contains "<li>stuff here</li>
". I realize also that the leading li tag may have parameters. The BIGGEST problem is that there might be multiple <li></li>
pairs in one line, especially if whoever wrote the HTML likes to have everything compressed and less human readable! ;)
I have thought a while about using things like string split, and going through the array of strings programatically, throwing a boolean flag to true when im in a <li>
tag, and false when i exit. Maybe this will work, but it feels very non-elegant.
How can i design a method that returns, say an ArrayList<String>
of all results? Can i do this without regex? I have looked up regex and it seems powerful, but sometimes the syntax can be very complicated. If i have to resort to regex i will, but simpler more clear solutions are appreciated!
If there is no elegant and clear way without regex, i will deal with the regex patterns.