Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:43:21+00:00 2026-06-17T08:43:21+00:00

I would like to add all numbers from the input to the coollection and

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:43:22+00:00Added an answer on June 17, 2026 at 8:43 am
    List<String> matchList = new ArrayList<String>();
    Pattern regex = Pattern.compile("-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)");
    Matcher regexMatcher = regex.matcher(subjectString);
    while (regexMatcher.find()) {
        matchList.add(regexMatcher.group());
    } 
    

    gives you an ArrayList of all regex matches. If I knew Java, I could probably show you how you could change that into an ArrayList of BigDecimals instead, but I guess you can do that yourself. Then just sort it.

    Explanation:

    -?          # Match an optional minus sign.
    (?:         # Either match:
     \d+        # a number,
     (?:\.\d+)? # optionally followed by a decimal part
    |           # or
     \.\d+      # just a decimal part
    )           # End of alternation
    

    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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add a GestureDetector to all views (view groups) of an
I have own project and i would like add for this class same as
I have a ListView and each item have a TextView. I would like add
I have a number of Eclipse projects that are all using classes from a
I have a ever growing csv file that looks like: 143100, 2012-05-21 09:52:54.165852 125820,
I would like to add a custom calculation method to a managed object (which
I would like to add roots to a VirtualTreeView http://www.delphi-gems.com/index.php/controls/virtual-treeview with a thread like
I would like to add a hash into an array using Ruby version 1.8.7:
I would like to add up the number of line changes in an SVN
I would like to add a pop effect when I hover over a SVG

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.