Created
February 6, 2019 22:00
-
-
Save CagriAldemir/b84c23dda755832aa7ce9fc1c544bc9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h4>An Unordered List:</h4> | |
<ul> | |
<li>Coffee</li> | |
<li>Tea</li> | |
<li>Milk</li> | |
</ul> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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