import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\{(if '?\\{?)?(.*?)_en-us(.*?)\\}";
final String string = "{exp:channel:entries channel=\"\" url_title=\"doors\" limit=\"1\"}\n\n"
+ "{exp:playa:children field=\"video_slider\" var_prefix=\"videoslider\"}\n"
+ " {if {videoslider:total_results} != '0'}\n"
+ " {if {videoslider:count}=='1'}\n"
+ " {if '{video_slider_title_en-us}'!='NULL'}\n"
+ " {video_slider_title_en-us}\n"
+ " {if:else}\n"
+ " Videos\n"
+ " {/if}\n"
+ " {/if}\n"
+ " {if video_thumb != ''}\n"
+ " {if:else}\n"
+ " {exp:url_tube:thumbnail src=\"{videoslider:video_file}\" width=\"334\" height=\"150\"}\n"
+ " {/if}\n"
+ " {if video_thumb_title != ''}\n"
+ " {video_thumb_title}\n"
+ " {if:else}\n"
+ " {videoslider:title}\n"
+ " {/if}\n"
+ " {if {videoslider:count}=={videoslider:total_results}}\n"
+ " {/if}\n"
+ "{/exp:playa:children}\n\n\n"
+ "{/exp:channel:entries}\n";
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