import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[\\r\\n]+\\[\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\.\\d+-\\d{2}:\\d{2}\\|info]\\*[^\\r\\n]+([\\r\\n]+)\\[\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\.\\d+-\\d{2}:\\d{2}\\|info\\]Line";
final String string = "[2019-12-18 07:00:01.070924-07:00|info]Line 3: :begin\n"
+ "[2019-12-18 07:00:01.070924-07:00|info]Line 4: \n"
+ "[2019-12-18 07:00:01.070924-07:00|info]Line 5: WORKINGDIR \"C:\\Download\\Server1\"\n"
+ "[2019-12-18 07:00:01.070924-07:00|info]*Working directory: C:\\Download\\Server1\\\n"
+ "[2019-12-18 07:00:01.070924-07:00|info]Line 6: \n"
+ "[2019-12-18 07:00:01.070924-07:00|info]Line 7: FTPLOGON \"Server1\" /timeout=60\n"
+ "[2019-12-18 07:00:01.070924-07:00|info]*Logging on to <server1> as SFTP (SSH File Transfer Protocol)\n"
+ "[2019-12-18 07:00:01.070924-07:00|info]*Logon in progress...\n"
+ "[2019-12-18 07:00:03.055523-07:00|info]*Logon successful.\n"
+ "[2019-12-18 07:00:03.055523-07:00|info]Line 8: FTPCD \"Extracts\"\n"
+ "[2019-12-18 07:00:03.164909-07:00|info]*Current FTP site directory: /Extracts/\n"
+ "[2019-12-18 07:00:03.164909-07:00|info]Line 9: IFERROR= $ERROR_SUCCESS GOTO Operation1\n"
+ "[2019-12-18 07:00:03.164909-07:00|info]Line 21: :Operation1\n"
+ "[2019-12-18 07:00:03.164909-07:00|info]Line 22: FTPGETFILE \"*na_alert_subs*\" /newest\n"
+ "[2019-12-18 07:00:03.164909-07:00|info]*Hint: FTPGETFILE /newest always returns the newest file\n"
+ "[2019-12-18 07:00:03.430561-07:00|info]Line 22: *%sitefile has been set to: na_alert_subs_20191217.txt\n"
+ "[2019-12-18 07:00:03.446223-07:00|info]Line 23: RCVFILE %sitefile /delete\n"
+ "[2019-12-18 07:00:03.446223-07:00|info]*Receiving to \"C:\\Download\\Server1\\na_alert_subs_20191217.txt\"\n"
+ "[2019-12-18 07:00:12.947244-07:00|info]*Complete, received 1394788 bytes in 9 seconds (1513.44K cps)\n"
+ "[2019-12-18 07:00:13.103506-07:00|info]*File deleted on FTP site.\n"
+ "[2019-12-18 07:00:13.103506-07:00|info]*Download complete, 1 file received.\n"
+ "\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