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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:27:38+00:00 2026-06-14T05:27:38+00:00

I am using java regex library to find a pattern String_OneOrMoreDigits. For example, linenumber_1

  • 0

I am using java regex library to find a pattern “String_OneOrMoreDigits”. For example, “linenumber_1” or “linenumber_31” or “linenumber_456”. I am trying the following pattern assuming I will get string of type “linenumber_2” or “linenumber_44”. However, I just get the strings of type “linenumber_2”, it does not match more than one number at the end. How to go about matching such strings?

Pattern pattern = Pattern.compile("(linenumber_[0-9])|(linenumber_[0-9][0-9])");

  • 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-14T05:27:40+00:00Added an answer on June 14, 2026 at 5:27 am

    No need for an alternation, just use a “one or more” qualifier on the [0-9]:

    Pattern pattern = Pattern.compile("linenumber_[0-9]+");
    

    That will match “linenumber_1” and “linenumber_44” and “linenumber_12345984”. If you only want to match one or two digits, you can do that by being more explicit about the number of digits allowed:

    Pattern pattern = Pattern.compile("linenumber_[0-9]{1,2}");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using java.util.regex.Pattern to match passwords that meet the following criteria: At least 7
I tried writing a program in Java using regex to match a pattern and
I need some help using regex in java. Im trying to achieve 2 different
I'd like to manipulate a String in Java using Regex. Goal is to find
Using java.util.regex.Pattern.compile() you can specify a pattern as parameter. But how can you specify
Using Java regex pattern I want to match the & symbol. But it should
I'm implementing a keyword highlighter in Java. I'm using java.util.regex.Pattern to highlight (making bold)
I am using java regex package to validate an email as below: Pattern p
Using java.util.regex.Matcher , are the following expressions for matched1 and matched2 equivalent? Is there
I am developing a text highlighter in a file using the java regex pattern

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.