The pattern should match all characters in the text.
- Between the Session and the date there is no space, but
"} | "
.
- The two date alternatives should not have spaces between them:
(data1|data2)
.
Regular expression
^\{([\dA-F]{8}(?:-[\dA-F]{4}){4}[\dA-F]{8})} \| (\d{2}/\d{2}/\d{4}|\d{4}-\d{2}-\d{2})
Description
^
- Circumflex that matches the beginning of the string.
\{
- Escape that houses a literal key "{"
.
([\dA-F]{8}(?:-[\dA-F]{4}){4}[\dA-F]{8})
- Capture group (capturing group) that allows you to reference married text (using Matcher#group(int)
) with:
[\dA-F]{8}(?:-[\dA-F]{4}){4}[\dA-F]{8}
- The format of Session, allowing only hexadecimal characters. We use a no-capture group to save some characters.
} \|
- House the literal "} | "
.
(\d{2}/\d{2}/\d{4}|\d{4}-\d{2}-\d{2})
- Capture group with two alternatives:
- Alternative 1:
\d{2}/\d{2}/\d{4}
.
- Alternative 2:
\d{4}-\d{2}-\d{2}
.
Code
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final String regex = "^\\{([\\dA-F]{8}(?:-[\\dA-F]{4}){4}[\\dA-F]{8})\\} \\| (\\d{2}/\\d{2}/\\d{4}|\\d{4}-\\d{2}-\\d{2})";
final String linha = "{E4AE5831-548B-4429-CB99-2429334A6348} | 16/03/2017 00:59:35 | [ColetaCPFVerificaColetaInicialReportCode] : [O seguinte prompt será vocalizad";
final Pattern p = Pattern.compile(regex);
final Matcher m = p.matcher(linha);
if(m.find()){
System.out.println(m.group(1));
System.out.println(m.group(2));
}
Upshot
E4AE5831-548B-4429-CB99-2429334A6348
16/03/2017
You can test here: http://ideone.com/qgRtt8
I edited your question by removing greetings as per this topic, to be in accordance with the website format
– user28595
Thank you! ... I’ll pay more attention :)
– Leandro Silva
If your or other answer was satisfactory, you can accept it as the answer to your question.
– vinibrsl