I have the following date / time format:
25/01 / 2017a1111: 53: 37
And the following regex:
REGX_DATAHORA_DISTRIBUICAO =
"(?<data>\d{1,2}\/\d{1,2}\/\d{4})|(?<hora>\d{1,2}:\d{1,2}:\d{1,2})"
private OffsetDateTime getDataDistribuicao() {
String textoData = replaceAndTrim(this.getPaginaInfoGerais().<HtmlTableCell>getFirstByXPath(XPATH_CEL_DATA_DISTRIBUICAO)
.getTextContent());
return LocalDateTime
.parse(getDataDistribuicao(textoData),
DateTimeFormatter.ofPattern(PATTERN_DATA_HORA))
.atOffset(ZoneOffset.UTC);
}
private String getDataDistribuicao(final String dataTexto) {
final Matcher matcherDataHora = REGX_DATAHORA_DISTRIBUICAO.matcher(dataTexto);
if (matcherDataHora.find()) {
return matcherDataHora.group();
} else {
throw new RegexException("Data distribuição", REGX_DATAHORA_MOVIMENTACAO.pattern(), dataTexto);
}
}
The regex has 2 groups, but only one group is returned, the one of the date. The other time group returns as null.
I suppose it's because of the operator ...
I've already tried to use (?=
( positive lookahead
), but maybe I used it wrong.
What to do?