import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "node.*?=(\\w+).*?\\s(\\d+)";
final String string = "digraph A {\n"
+ "rankdir = LR;\n"
+ "node [shape=circle,style=filled] 0\n"
+ "node [shape=circle,style=filled] 1\n"
+ "node [shape=circle,style=filled] 2\n"
+ "node [shape=circle,style=filled] 3\n"
+ "node [shape=circle,style=filled] 4\n"
+ "node [shape=circle,style=filled] 5\n"
+ "node [shape=circle,style=filled] 6\n"
+ "node [shape=circle,style=filled] 7\n"
+ "node [shape=circle,style=filled] 8\n"
+ "node [shape=circle,style=filled] 9\n"
+ "node [shape=doublecircle,style=filled] 10\n"
+ "0 -> 4 [label=\"g \"];\n"
+ "0 -> 1 [label=\"b \"];\n"
+ "1 -> 2 [label=\"o \"];\n"
+ "2 -> 7 [label=\"y \"];\n"
+ "2 -> 3 [label=\"o \"];\n"
+ "3 -> 7 [label=\"k \"];\n"
+ "4 -> 5 [label=\"i \"];\n"
+ "5 -> 6 [label=\"r \"];\n"
+ "6 -> 7 [label=\"l \"];\n"
+ "7 -> 9 [label=\"<+N:s> \"];\n"
+ "7 -> 8 [label=\"<+N:0> \"];\n"
+ "8 -> 10 [label=\"<+Sg:0> \"];\n"
+ "9 -> 10 [label=\"<+Pl:0> \"];\n"
+ "}";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
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