import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(<\\!\\-\\- wp:onecms\\/recipe-time \\{\\\"type\\\"\\:\\\"cook\\\")\\S(.*[a-z\\:0-9\\}\\s])(\\/\\-\\->)$";
final String string = "<!-- wp:onecms/recipe-header {\"dek\":\"\\u003cp\\u003eHungry for some \\u003ca href=\\u0022https://www.southernliving.com/recipes/old-fashioned-apple-pie\\u0022\\u003eapple pie\\u003c/a\\u003e? We are right there with you. Here's the recipe from the Whispering Canyon Café at Disney’s Wilderness Lodge—dessert will never be the same.\\u003c/p\\u003e\"} /-->\n\n"
+ "<!-- wp:onecms/primary-media /-->\n\n"
+ "<!-- wp:onecms/recipe-media /-->\n\n"
+ "<!-- wp:onecms/recipe-container -->\n"
+ "<!-- wp:onecms/recipe-details -->\n"
+ "<!-- wp:onecms/recipe-metadata {\"yieldDescription\":\"Makes one 9-inch pie.\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-times -->\n"
+ "<!-- wp:onecms/recipe-time {\"type\":\"hands-on\",\"days\":0,\"hours\":0,\"minutes\":45} /-->\n\n"
+ "<!-- wp:onecms/recipe-time {\"type\":\"cook\",\"days\":0,\"hours\":1,\"minutes\":0} /-->\n"
+ "<!-- /wp:onecms/recipe-times -->\n"
+ "<!-- /wp:onecms/recipe-details -->\n\n"
+ "<!-- wp:onecms/recipe-ingredients -->\n"
+ "<!-- wp:onecms/recipe-section-header {\"content\":\"Pie Crust\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"butter, cut into small pieces\",\"customMeasure\":\"tablespoons\",\"customQuantity\":\"4\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"shortening\",\"customMeasure\":\"cup\",\"customQuantity\":\"0.25\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"all-purpose flour\",\"customMeasure\":\"cups\",\"customQuantity\":\"1.75\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"sugar\",\"customMeasure\":\"teaspoons\",\"customQuantity\":\"4\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"coarse salt\",\"customMeasure\":\"teaspoon\",\"customQuantity\":\"0.13\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"2% milk\",\"customMeasure\":\"cup\",\"customQuantity\":\"0.33\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-section-header {\"content\":\"Apples\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"water\",\"customMeasure\":\"cup\",\"customQuantity\":\"1\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"Granny Smith apples, peeled and sliced\",\"customQuantity\":\"6\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"apple pie spice\",\"customMeasure\":\"teaspoon\",\"customQuantity\":\"2\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-section-header {\"content\":\"Apple Pie Batter\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"butter, softened\",\"customMeasure\":\"cup\",\"customQuantity\":\"0.5\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"sugar\",\"customMeasure\":\"cup\",\"customQuantity\":\"0.67\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"eggs\",\"customQuantity\":\"2\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"flour\",\"customMeasure\":\"cups\",\"customQuantity\":\"1.5\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"baking powder\",\"customMeasure\":\"teaspoon\",\"customQuantity\":\"1.5\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"salt\",\"customMeasure\":\"teaspoon\",\"customQuantity\":\"0.13\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-ingredient-custom {\"customIngredient\":\"heavy cream\",\"customMeasure\":\"cup\",\"customQuantity\":\"0.25\"} /-->\n"
+ "<!-- /wp:onecms/recipe-ingredients -->\n\n"
+ "<!-- wp:onecms/recipe-nutrition {\"displayNutritionRecipe\":false} /-->\n\n"
+ "<!-- wp:onecms/recipe-directions -->\n"
+ "<!-- wp:onecms/recipe-direction {\"directionId\":\"ddaa1eec-7bec-4284-b4e3-53b35cb83941\",\"content\":\"\\u003cstrong\\u003eFOR PIE CRUST: \\u003c/strong\\u003e\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-direction {\"directionId\":\"e546e3c3-96a5-4be5-94fa-34ee625f3a48\",\"content\":\"\\u003cstrong\\u003eFOR APPLES:\\u003c/strong\\u003e\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-direction {\"directionId\":\"49fbc0c6-12f0-420c-9dc6-19210620e023\",\"content\":\"\\u003cstrong\\u003eFOR APPLE PIE BATTER:\\u003c/strong\\u003e\"} /-->\n\n"
+ "<!-- wp:onecms/recipe-direction {\"directionId\":\"208717df-e3e3-43e9-a2bc-35ad854ae43c\",\"content\":\"\\u003cstrong\\u003eFOR APPLE PIE:\\u003c/strong\\u003e\"} /-->\n"
+ "<!-- /wp:onecms/recipe-directions -->\n\n"
+ "<!-- wp:onecms/recipe-notes -->\n"
+ "<!-- wp:onecms/recipe-note /-->\n"
+ "<!-- /wp:onecms/recipe-notes -->\n"
+ "<!-- /wp:onecms/recipe-container -->";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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