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

  • Home
  • SEARCH
  • 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 6605891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:20:14+00:00 2026-05-25T19:20:14+00:00

I am learning RegEx. completely a newbie :P I wanted to separate numbers from

  • 0

I am learning RegEx. completely a newbie 😛

I wanted to separate numbers from the below data, which are separated by comma only

test
t,b
45,49
31,34,38,34,56,23,,,,3,23,23653,3875,3.7,8.5,2.5,7.8,2., 6 6 6 6 ,
,
.
.,/;,jm.m.,,n ,sdsd, 3,2m54,2 4,2m,ar ,SSD A,,B,4D,CE,S4,D,2343ES,SD

Suppose I am getting the above data from Form text field. Now I want to read the data only which are numbers seperated by comma

Solution should be[string]

45,49,31,34,38,34,56,23,3,23,23653,3875

all other data should be skipped.
I tried something like this ^[0-9]+\,$

But it’s also selecting 7 from 3.7, and 5 from 8.5, etc…..

Can anyone help me out in solving this!!

  • 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-05-25T19:20:15+00:00Added an answer on May 25, 2026 at 7:20 pm

    Assuming you are already splitting at commas and try to check whether the elements you get are numbers, use this expression: ^\d+(?:\.\d+)?$, which means: “must begin with digits potentially followed by a dot and at least one more digit”.

    This would match 31 as well as 7.8, but not 2., 6 6 6 6 or 2m54.

    Here’s a part by part explanation of that expression:

    • ^ means: matches must start at the first character
    • $ means: matches must end at the last character, so both together mean the entire string must match
    • \d+ means: one or more digits
    • (?: ... ) is a non-capturing group allowing to apply the ? quantifier
    • \. means: the literal dot
    • (?:\.\d+)? thus means: zero or one occurences of a dot followed by at least one digit

    Edit: if you only want integer numbers, just remove the group: ^\d+$ -> entire input must be one or more digits.

    Edit 2: If you can prepend and append a comma to the input string(see Edit 4), you should be able to use this regex for getting all numbers: (?<=,)\s*(\d+(?:\.\d+)?)\s*(?=,) (integers only would require you to remove the (?:\.\d+)? part).

    That expression gets all numbers between two commas with possible whitespace between the commas and the number and catches the number into a group. This should prevent matches of 6 6 6 6 or 2m54. Then just iterate over the matches to get all the groups.

    Edit 3: Here’s an example with your input string.

    String input = "test\n" +
            "t,b\n" +
            "45,49\n" +
            "31,34,38,34,56,23,,,,3,23,23653,3875,3.7,8.5,2.5,7.8,2., 6 6 6 6 ,\n" +
            ",\n" +
            ".\n" +
            ".,/;,jm.m.,,n ,sdsd, 3,2m54,2 4,2m,ar ,SSD A,,B,4D,CE,S4,D,2343ES,SD\n";
    
    Pattern p = Pattern.compile( "(?<=,|\\n)\\s*(\\d+(?:\\.\\d+)?)\\s*(?=,|\\n)" );    
    
    Matcher m = p.matcher( input );
    
    List<String> numbers = new ArrayList<String>();
    
    while(m.find())
    {
      numbers.add( m.group( 1 ) );
    }
    
    System.out.println(Arrays.toString( numbers.toArray() ));
    
    //prints: [45, 49, 31, 34, 38, 34, 56, 23, 3, 23, 23653, 3875, 3.7, 8.5, 2.5, 7.8, 3]
    //removing the faction group: [45, 49, 31, 34, 38, 34, 56, 23, 3, 23, 23653, 3875, 3]
    

    Edit 4: actually, you don’t need to add commas, just use this expression:

    `(?<=,|\n|^)\s*(\d+)\s*(?=,|\n|$)`
    

    The groups at the start and end mean the match must follow the start of the input, a comma or a line break and be followed by the end of the input, a comma or a line break.

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

Sidebar

Related Questions

I've been learning regex with java. I wanted to know if it makes sense
I'm learning RegEx and site crawling, and have the following question which, if answered,
I've been learning Regex/grep from the BBEdit manual, and it's been smooth sailing except
I'm learning/practicing Regex. I've written this to test for url's...I want it to catch
I'm learning regex, and I can't understand the grouping in Java. Currently my regex
Good afternoon, I'm learning about using RegEx's in Ruby, and have hit a point
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is
I am not very good with Regex but I am learning. I would like
Learning from my last question , most member names seem to get included in
As an exercise in learning RegEx in JavaScript, I've been trying to select an

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.