import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?<name_of_new_field>.+?)\\.";
final String string = "ir7utbws001.Feb-12-2016.043./dev/sdi \n"
+ "ir7mojavs12.Feb-12-2016.043./dev/sda1 \n"
+ "Gcase-field-ogs-batch-004-staging.dec-12-2016.043 \n"
+ "sb7sdamb002.Feb-12-2016.043./dev/sdn \n"
+ "ebase73-ist-bat-002.Feb-12-2016.043./dev/sda1 \n"
+ "ik2itpcp002.Feb-12-2016.043./dev/sda1 \n"
+ "ebase-field-ods-batch-003.Feb-12-2016.043./dev/sdi \n"
+ "Leo-batch-001.Feb-12-2016.043./dev/sda1 ";
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