Bom dia!
O papel deste cara não é retornar a quantidade de GRUPOS encontrados em um deternimado
MATCHER?
Pq. então sempre me retorna '0' quando tenho vários grupos?
Alguém pode me mostrar um exemplo?
Desde já agradeço.
[color=red]A String é essa e, contém 5 (Cinco) grupos válidos[/color]
03/01/05 07:18AM 1 E1148 T10103 <I>9000 0'10 00:00'25
03/01/05 07:37AM 1 E1089 T10101 25579700 00:02'16
03/01/05 07:52AM 1 E1031 T10101 22640484 00:03'24
03/01/05 07:54AM 1 E1082 T10101 25340311 00:00'55
03/01/05 07:58AM 1 E1148 T10923 <I>3777 0'07 00:00'16
********************************************************************************
Date Time T E
//Separa registro válido
Matcher mtchRegistro = Pattern.compile("/.*\n\r").matcher(sbBuffer1);
//
while (mtchRegistro.find()) {
//Total de Grupos encontrados
System.out.println(mtchRegistro.groupCount());
System.out.printf("Encontrado: \"%s\" de %d à %d.%n", mtchRegistro.group(), mtchRegistro.start(), mtchRegistro.end());
//Grava registro tratado
gravaRegistro(trataRegistro(cb.toString().substring(mtchRegistro.start() - 2, mtchRegistro.end() - 2)));
}
Você não pôs na sua expressão regular os caracteres para agrupamento, “(” e “)”.
Perdoe-me!
Não entendi!
Irei procurar por isso agora mesmo.
Dica: veja o site do Aurélio, http://aurelio.net/er/ . Ele não fala exatamente sobre Java, mas o que você aprender lá vai ser extremamente útil.
Não entendi muito bem, pra começar, o que você quer “bater” na sua expressão regular.
Blz!, irei olhar o Aurélio.
Antes.
Assim funciona, porém só me diz que tem apenas um grupo quando deveria dizer 5.
//Separa registro válido
Matcher mtchRegistro = Pattern.compile("(/.*\n\r)").matcher(sbBuffer1);
Acho que o problema está no Pattern.
Por favor, dê uma olhada nesse exemplo.
input =
"Humpty Dumpty sat on a wall. " +
"Humpty Dumpty had a great fall. " +
"All the king's horses and all the king's men " +
"Couldn't put Humpty together again! " ;
pattern = Pattern.compile( "((H|D)(umpty) ){2}" );
// Matches six characters ending in "umpty" and
// beginning with "H" or "D". Three capturing
// groups are defined and remembered by the Matcher.
matcher = pattern.matcher( input );
System.out.println( matcher.find() ); // Prints true.
System.out.println( matcher.groupCount() ); // Prints 3.
System.out.println( matcher.group( 1 ) ); // Prints "Dumpty ".
System.out.println( matcher.group( 2 ) ); // Prints "D".
System.out.println( matcher.group( 3 ) ); // Prints "umpty".
System.out.println( matcher.group( 0 ) ); // Prints "Humpty Dumpty ".
// If it was expected that matcher.group( 1 ) should contain
// "Humpty", then remember that the group( int ) method
// returns the input subsequence captured by the specified
// group during the previous match operation. This match
// operation was performed two times - the first time matching
// "Humpty" and the second time matching "Dumpty".
Por favor!
Porquê não consigo encontrar os cinco GRUPOS na string?
Preciso muito desta informação.
Valeu!