import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^\\040*)(\\w*)(\\040*)(=)(\\040*)(\\w*$|\".*)";
final String string = "# '#' character is used for comments - like in Bash\n"
+ "# '*' character is a wildcart character, \".*\" is the regex equivalence\n\n"
+ "# set x-ambles, the strings to be printed before, in-between and after the group of bitfields\n"
+ "preamble=\"#ifdef DEBUG\"\n"
+ "interamble=#else\n"
+ "postamble=#endif\n\n"
+ "# set the alignment value\n"
+ "alignment=16\n\n"
+ "# bitfield names to be ignored\n"
+ "ignore=padding*,dummy*,doNotCare* \n\n"
+ "# indent \n"
+ "indent=\" \"\n\n"
+ "# padding type\n"
+ " padding = unsigned\n\n"
+ "# this whould not be searched by C++ engine \n"
+ "files=*.h,*.c\n\n"
+ "#prefix of type name to be searched\n"
+ "prefix=typedef\n\n"
+ "#do or do not mirror\n"
+ "mirror=true\n\n"
+ "#for regex testig\n"
+ "mirror=$\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