import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<td>[A-Z0-9-]+<\\/td>";
final String string = "<table class=\"stripeMe\">\n"
+ " <tbody>\n"
+ " <tr>\n"
+ " <th>Image</th>\n"
+ " <th>Part#</th>\n"
+ " <th>Original#</th>\n"
+ " <th>Description</th>\n"
+ " </tr>\n"
+ " <tr class=\"alt\">\n"
+ " <td>\n"
+ " <a href=\"/item/8438657/High_Capacity/AC-C27/18_TO_20_VOLT_65_WATT_AC_ADAPT\"><img width=\"75\" height=\"75\" title=\"AM11X-2719 18 TO 20 Volt 65 Watt AC Adapter\" src=\"/shop/images/image.php?img=BAT\\8438657.jpg&thumbnail=Y\"></a>\n"
+ " </td>\n"
+ " <td><a title=\"AM11X-2719 18 TO 20 Volt 65 Watt AC Adapter\" href=\"/item/8438657/High_Capacity/AC-C27/18_TO_20_VOLT_65_WATT_AC_ADAPT\">AC-C27</a></td>\n"
+ " <td>TR82J</td>\n"
+ " <td>18 TO 20 Volt 65 Watt AC Adapter</td>\n"
+ " </tr>\n"
+ " <tr class=\"\">\n"
+ " <td>\n"
+ " <a href=\"/item/10242499/High_Capacity/DRAC90B/DURACELL_90W_19V_UNIVERSAL_NOT\"><img width=\"75\" height=\"75\" title=\"AM11X-2719 Duracell 90W 19V Universal Notebook AC Adapter\" src=\"/shop/images/no_picture_thumb.jpg\"></a>\n"
+ " </td>\n"
+ " <td><a title=\"AM11X-2719 Duracell 90W 19V Universal Notebook AC Adapter\" href=\"/item/10242499/High_Capacity/DRAC90B/DURACELL_90W_19V_UNIVERSAL_NOT\">DRAC90B</a></td>\n"
+ " <td>331-0536</td>\n"
+ " <td>Duracell 90W 19V Universal Notebook AC Adapter</td>\n"
+ " </tr>\n"
+ " </tbody>\n"
+ "</table>";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html