Frage

String :

"75,000", "is", "95%", "or", "95/100" "of", "monthly", "income"

o/p :

"is","%, "or", "/", "of", "monthly", "income"

i am trying below : In for loop

        if (String.matches("[\\d]*[.,]*[\\d%]"))
                {   
                    String = String.replaceAll("[\\d]*[.,]*[\\d%]","");
                    String.previous();
                    String.set(token);
                    String.remove();
                    String.next();
                }

but it is not picking up numbers at all.

Help will be appreciated

War es hilfreich?

Lösung

Try this pattern:

(\\d+[,/%]?\\d*)

Matches:
75,000
95%
95/100


or

"(\\d+,\\d+)|\\d+"

MAtches:

75,000
95
100
(digit),(digit) or digit

This pattern:

[^\\d,]+  or eventually [^\\d,\\"]+

Matches:

is
%
or
/
of
monthly
income

Andere Tipps

Try this regular expression :

"\\d*[.,]?\\d+%?"

Try

"\\d*[.,]?\\d+%"

This will match a number with an optional , or . and a % at the end. If you want to match numbers, which can end in a % or not, just add a ? at the end.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top