import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "#\\{(\\w+[.\\w+]+)\\}";
final String string = "The [#{product.name}](/card-details/card-name/#{details.slug.value}) which has an annual fee of #{details.annual_fee.value}, does double-duty as a rewards credit card and a balance transfer credit card. You’ll get a big sign-up bonus: Discover will automatically double cash back for new card holders in your first year. Plus, when you opt in to a bonus rewards program, this card earns 5% cash back on rotating bonus categories like gas and restaurants. Be aware that these 5% rewards are capped at $1,500 spent per quarter. On all other purchases, you’ll get 1% cash back. There is #{details.pros_bullets.value.1} and it comes with a generous 0% APR offer: #{details.apr_intro_message_list.value.0}. The card charges a 3% balance transfer fee, and Discover isn’t widely accepted abroad. But it could be a great choice if you’re trying to earn big rewards on new purchases while paying off an old debt.";
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