I would like to add all numbers from the input to the coollection and sort them.
I have input file like that:
12i -+3456i
78,i910
11
i-12i
13.14r
15.r16r
i17.18
-+19.20
+r21.22
+23.242526r
+-27.28r
-29.30r
-.313233r
r-0.343536rr
r.34r
3536.r
r+37.38
Liczba -0.1234 jest mniejsza niz liczba .2 i wieksza niz liczba -1;
i123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789i
Of course there are Integers, Doubles, BigIntegers etc. I would like to put them into Collection and sort. This is not hard if I make 3 passes through this input:
1. Create regex for integers and filter the input add those integers into collection
2. Create regex for doubles and filter the input add those doubles into collection
3. Create regex for bigIntegers and filter the input add those bigIntegers into collection
4.Sort this collection of BigDecimals.
But this seems to be stupid. Is there any way to put all those numbers into collection in one pass through the input? Using regex.
EDIT:
12,12 == 12.12 --> double
12i --> i does not count this is integer 12
EDIT2:
Correct output order
-29.30
-27.28
-12
-1
-0.343536
-0.313233
-0.1234
0.2
0.34
11
12
13.14
15
16
17.18
19.20
21.22
23.242526
37.38
78
910
3456
3536
123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
gives you an
ArrayListof all regex matches. If I knew Java, I could probably show you how you could change that into anArrayListof BigDecimals instead, but I guess you can do that yourself. Then just sort it.Explanation:
See it in action at regex101.
(Edit: New version that doesn’t produce lots of empty matches (the old one was matching the empty string, too)