import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^#+\\s*(.*?)\\{#(.*)\\}";
final String string = "# Scoring import {#calculate-score}\n\n"
+ "Loads Scoring*csv files from the WebDAV and import them locally.\n"
+ "While processing and when finished, the file gets renamed on the WebDAV.\n\n"
+ "# Response export {#unsubscribe-export}\n\n"
+ "Exports unsubscribes, bounces and complaints and stores the export files \n"
+ "on an SFTP of the customer.\n\n"
+ "# Campaign uploader {#15mins-campaign-uploader}\n\n"
+ "Fetches a ZIP from the customers SFTP. \n"
+ "This ZIP must contain a JSON and a HTML. Images must be stored in a `img` \n"
+ "folder. Size limit for an image is 1 MB. Images will be uploaded to the \n"
+ "Suite media library. Campaign meta data will be read from the JSON.\n\n"
+ "**This process is currently deactivated** \n\n\n"
+ "# ecard invite a friend landing page {#recommendation-form}\n\n"
+ "A form to invite friends. The friends data will be stored in the Suite account.\n\n"
+ "# Pretrip form {#pretrip-information-form}\n\n"
+ "Asking the end user to provide more more data before they arrive.\n\n"
+ "# Signup pages and preference center {#preference-center}\n\n"
+ "Pages to subscribe and to manage personal data.";
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