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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:11:54+00:00 2026-06-16T07:11:54+00:00

I need to find if a String starts with abcd followed by 1-5 digits,

  • 0

I need to find if a String starts with “abcd” followed by 1-5 digits, then a comma, then ends with 0-3 digits.

    Pattern pattern = Pattern.compile("abcd[0-9]{1,5},[0-9]{0,3}$");

    String[] data = { "pqrsabcd12345,5", "abcd1234,5", "abcd1234542155,",
            "abcdSD12345,555", "abcd123,555", "abcd12,5555",
            "abcd,5555ffdfd", "abcd2,5555ffdfd", "abcd2,5" };
    for (CharSequence input : data) {
        Matcher matcher = pattern.matcher(input);
        while (matcher.find()) {
            System.out.format("\nI found the text  %s :"
                    + " \"%s\" starting at "
                    + "index %d and ending at index %d.%n", input,
                    matcher.group(), matcher.start(), matcher.end());
        }
    }

The output :

I found the text  pqrsabcd12345,5 : "abcd12345,5" starting at index 4 and ending at index 15.

I found the text  abcd1234,5 : "abcd1234,5" starting at index 0 and ending at index 10.

I found the text  abcd123,555 : "abcd123,555" starting at index 0 and ending at index 11.

I found the text  abcd2,5 : "abcd2,5" starting at index 0 and ending at index 7.

Using this, I could ensure the ends with part. I think I am left with stopping Strings like "pqrsabcd12345,5"

Please let me know if I have missed something.

  • 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-16T07:11:56+00:00Added an answer on June 16, 2026 at 7:11 am

    You just need a little modification to your regex: –

    "^abcd[0-9]{1,5},[0-9]{0,3}$"
    

    You forgot to use Caret – ^ to ensure that the pattern is matched at the start of your string.

    Alternatively, you can also use Matcher#matches() instead of Matcher#find() method, if you want your pattern to match at the ends. That way you won’t need to use anchors.

    So, the difference between matches() and find() can be easily shown with your string that is not satisfying your requirement: –

    // pattern is the reference you are having
    pattern.matcher("pqrsabcd12345,5").find(); // Will return true
    pattern.matcher("pqrsabcd12345,5").matches(); // Will return false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find in a text everything that starts with [ and ends
I'm using this regex to find a String that starts with !?, ends with
I need to find the longest sequence in a string with the caveat that
I have a string and I need to find out whether it is a
I have a large string I need to parse, and I need to find
Given a user input string, I need to find if it end with one
I need to be able to search within a string and find out if
Hello , I have text and I need to find in it a string
I need to collect some data and temporarily store it in memory and then
I have a string #letme.doit.now .emiter #another.test #plus.test. I need to find all dots

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.