import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*Function=\\\"([^\\\"]*).*";
final String string = "[1] ID=Gfo_R000001;Source=ENST00000513418;Function=\"SMAD5\"; \n"
+ "[2] ID=Gfo_R000002;Source=ENSTGUT00000017468;Function=\"CENPA\";\n"
+ "[3] ID=Gfo_R000003;Source=ENSGALT00000028134;Function=\"C1QL4\";\n"
+ "[4] ID=Gfo_R000004;Source=ENSTGUT00000015300;Function=\"\"; \n"
+ "[5] ID=Gfo_R000005;Source=ENSTGUT00000019268;Function=\"\"; \n"
+ "[6] ID=Gfo_R000006;Source=ENSTGUT00000019035;Function=\"\"; \n";
final String subst = "\\1";
final Pattern pattern = Pattern.compile(regex);
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