import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\d)(-\\d*\\.)";
final String string = "1 0.00000E+00-7.52896E-04 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 1.00247E-01 0.00000E+00\n"
+ "9 2.57945E+00-9.98377E-04 0.00000E+00 1.80923E+02 0.00000E+00 0.00000E+00 1.08995E+03 0.00000E+00 0.00000E+00 1.00795E+01 1.00002E-01 0.00000E+00\n"
+ "18 2.37285E+00-2.20000E-01 0.00000E+00 1.81079E+02-5.53001E+00 0.00000E+00 1.30827E+03 2.01207E+03 0.00000E+00 9.87285E+00 8.64615E-01 0.00000E+00";
final String subst = "\\1 \\2";
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