3
I have the following input:
Fatura Cliente: 1.7852964.34
CPF/CNPJ: 09022317000222
I need to take only the "Customer Invoice" numbers, ignoring scores, returning only 1785296434
, for this I am using the following regex:
Fatura Cliente[\D]+(\S+)
But later I need to treat and replace the scores to turn into a sequence of numbers.
How do I get regex to give me a sequence of numbers ignoring scores by capture group without having to replace the code later?
Capturing by the first regex already formatted without the scores is possible or necessary to give a String.replace or String.replaceAll(regex) after the first capture with regex?
It is a substring capturing a string using regex, and in this capture regex of this substring already wanted the sequence of formatted numbers to come, without points and commas. I capture the substring using regex "Customer Invoice[ D]+(? <clientNumber> S+" and matcher.group("clientNumber") is "6.823935.10", but I need it already formed without points and commas: "682393510", understands?
– Gustavo Piucco
Have you tried using replace on each Submatch? I have no experience in java, but it would be something like:
String TirarPonto = SubMatchDoRegex.replace(".", "");
– danieltakeshi
At first I wanted capture group matcher.group("clientNumber") to return with it formatted by regex itself. And yes, this is the way I’m using today, it serves me for now, but the doubt is more curious than need, and also to make the code cleaner in the future, because I use very regex.
– Gustavo Piucco
You would need an extra step to handle this. It is not possible to do only with Regex.
– danieltakeshi
Perfect. Basically what I needed to know was that it is not possible, so the only output then is to format with a String.replace or string.replaceAll(regex) after capturing the string with the numbering + score. I will edit the initial question, then you can edit your answer and inform that it is not possible to capture it formatted directly. This way I can mark how accepted to help future users who come to have the same question.
– Gustavo Piucco