Last active
December 1, 2015 10:14
-
-
Save hitenpratap/32c58023a95c6a1c8afa to your computer and use it in GitHub Desktop.
Extract particulars tags from String using regex
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
package com.hprog99; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class ExtractStrTag { | |
private static Pattern tagPattern = | |
Pattern.compile("<imageTag>(.+?)</imageTag>"); //here replace <imageTag> with your required tag | |
public static List<String> getTagList(String str){ | |
final List<String> tagValues = new ArrayList<String>(); | |
final Matcher matcher = tagPattern.matcher(details); | |
while (matcher.find()) { | |
tagValues.add(matcher.group(1)); | |
} | |
return tagValues; | |
} | |
public static void main(String pwds[]){ | |
String rawString = "<p><em><strong>gfbgbtyhmjtu myu mty mut ,uy ,rutm yjnhrt hdtjgher gerugfrhjs gfsjrbgvhfdsgf yergf egbvhrg fgyes</strong></em></p>\n" + | |
"<p><imageTag>1895409.jpg</imageTag></p>\n" + | |
"<p><strong>bfrttttttthbulgihdtyhblthigltnliytkmityumiytj ytmjkd yjmrum kk76yj rutkmu,m ryukm,iy, r</strong></p>\n" + | |
"<p><imageTag>1369106.jpg</imageTag></p>"; | |
System.out.println(getTagList(rawString)); | |
} | |
} | |
//Output will be something like this | |
//["1895409.jpg","1369106.jpg"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment