import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\[(?P<key>.+?)(?:\\s+(?P<settings>.*?))?\\]";
final String string = "### The I_Soil System\n\n"
+ "The I-soil material model is a nonlinear hysteretic soil model that is based on the distributed\n"
+ "element models developed by [!citet](iwan1967on) and [!citet](chiang1994anew). In 1-D, this model takes\n"
+ "the backbone stress-strain curve and divides it into a set of elastic-perfectly plastic curves. The\n"
+ "total stress then is the sum of the stresses from the individual elastic-perfectly plastic curves.\n\n"
+ "The three dimensional generalization of this model is achieved using von-Mises failure criteria for\n"
+ "each elastic-perfectly plastic curve resulting in an invariant yield surfaces in three-dimensional\n"
+ "stress space like in [fig:yieldsurface] (after [!citet](chiang1994anew)).";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE);
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