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 9185131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:13:09+00:00 2026-06-17T19:13:09+00:00

I need to find digits between , and , in all text. I dont

  • 0

I need to find digits between "," and ","in all text.
I dont want to use .split() and want to do it with regexp.
I can easily get all matches with something like that:

Pattern.compile(",?(\\d+),")

The question is, can I get only second(or third, or forth) match?
I dont need to parse all text, I’d like to stop after N matches.
Is it possible?

  • 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-17T19:13:10+00:00Added an answer on June 17, 2026 at 7:13 pm

    Here is an example on how to get the 5th match:

        String input = "11,22,33,44,55,66,77,88,99";
        Pattern pattern = Pattern.compile(",?(\\d+),");
        Matcher matcher = pattern.matcher(input);
        int counter = 0;
        int wantedMatch = 5;
        while (matcher.find()) {
            counter++;
            if (counter == wantedMatch) {
                String digits = matcher.group(1);
                System.out.println(digits); // prints 55 
                break; // stop searching after n matches.
            }
        }
        if (counter < wantedMatch) {
            System.out.println("You wanted match #" + wantedMatch + ", there only were " + counter);
        }
    

    Adapt it to your needs

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

Sidebar

Related Questions

I need to find all matches of word which strictly begins with $ and
I need to find all the occurences of a file Test.TXT in c:\ or
I need to find a way to get actual page size in Google Chrome.
I need to find lines that are 3 digits and 3 other characters: I
I have an integer and need to find out how many digits are in
I need to find the number of digits of very large multiplications (about 300
I need to find out the number of digits which are not divisible by
All, I can't seem to find the answer I'm looking for using search so
I need to find if a String starts with abcd followed by 1-5 digits,
I got some text that changes dynamically and I need a way to find

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.