import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((maildir=cipec\\.com\\.br.*\\/)|(clearpasswd.*\\,))";
final String string = "3-Sep 1 08:40:59 srvmail authdaemond: password matches successfully\n"
+ "4-Sep 1 08:40:59 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=helio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/helio/, quota=<null>, options=<null>\n"
+ "5:Sep 1 08:40:59 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=pdsPDnYTP3gyw\n"
+ "6-Sep 1 08:40:59 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=helio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/helio/, quota=<null>, options=<null>\n"
+ "7:Sep 1 08:40:59 srvmail authdaemond: Authenticated: clearpasswd=hel733, passwd=pdsPDnYTP3gyw\n"
+ "8-Sep 1 08:40:59 srvmail pop3d: LOGIN, user=helio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[46999]\n"
+ "9-Sep 1 08:40:59 srvmail pop3d: LOGOUT, user=helio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[46999], top=0, retr=0, rcvd=12, sent=39, time=0\n"
+ "--\n"
+ "42-Sep 1 08:41:02 srvmail authdaemond: password matches successfully\n"
+ "43-Sep 1 08:41:02 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=antonio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/antonio/, quota=<null>, options=<null>\n"
+ "44:Sep 1 08:41:02 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=pdiHUG4qjaDnI\n"
+ "45-Sep 1 08:41:02 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=antonio@cipec.com.br, fullname=<null>, maildir=cipec.com.br/antonio/, quota=<null>, options=<null>\n"
+ "46:Sep 1 08:41:02 srvmail authdaemond: Authenticated: clearpasswd=ant527, passwd=pdiHUG4qjaDnI\n"
+ "47-Sep 1 08:41:02 srvmail pop3d: LOGIN, user=antonio@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47004]\n"
+ "48-Sep 1 08:41:02 srvmail postgrey[1708]: action=pass, reason=client AWL, client_name=cipec.com.br, client_address=201.48.59.65, sender=return@bonustelecom.com.br, recipient=bianca@cipec.com.br\n"
+ "--\n"
+ "73-Sep 1 08:41:04 srvmail authdaemond: password matches successfully\n"
+ "74-Sep 1 08:41:04 srvmail authdaemond: authmysql: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=davi@cipec.com.br, fullname=<null>, maildir=cipec.com.br/davi/, quota=<null>, options=<null>\n"
+ "75:Sep 1 08:41:04 srvmail authdaemond: authmysql: clearpasswd=<null>, passwd=u3WErgO7RPtDc\n"
+ "76-Sep 1 08:41:04 srvmail authdaemond: Authenticated: sysusername=<null>, sysuserid=5000, sysgroupid=5000, homedir=/home/vmail, address=davi@cipec.com.br, fullname=<null>, maildir=cipec.com.br/davi/, quota=<null>, options=<null>\n"
+ "77:Sep 1 08:41:04 srvmail authdaemond: Authenticated: clearpasswd=dav510, passwd=u3WErgO7RPtDc\n"
+ "78-Sep 1 08:41:04 srvmail pop3d: LOGIN, user=davi@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47017]\n"
+ "79-Sep 1 08:41:04 srvmail pop3d: LOGOUT, user=davi@cipec.com.br, ip=[::ffff:10.0.1.103], port=[47017], top=0, retr=0, rcvd=12, sent=39, time=0\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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