Skip to content

Instantly share code, notes, and snippets.

@CagriAldemir
Created February 6, 2019 22:00
Show Gist options
  • Save CagriAldemir/b84c23dda755832aa7ce9fc1c544bc9e to your computer and use it in GitHub Desktop.
Save CagriAldemir/b84c23dda755832aa7ce9fc1c544bc9e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<h4>An Unordered List:</h4>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test{
private static final Pattern TAG_REGEX = Pattern.compile("<li>(.+?)</li>");
public static void main(String []args){
String str="<!DOCTYPE html><html><body><h4>An Unordered List:</h4><ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul></body></html>";
System.out.println(Arrays.toString(getTagValues(str).toArray()));
}
private static List <String> getTagValues(String str){
List <String> tagValues = new ArrayList<String>();
Matcher matcher = TAG_REGEX.matcher(str);
while(matcher.find()){
tagValues.add(matcher.group(1));
}
return tagValues;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment