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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:36:01+00:00 2026-06-16T08:36:01+00:00

Hello I have a question about RegEx. I am currently trying to find a

  • 0

Hello I have a question about RegEx. I am currently trying to find a way to grab a substring of any letter followed by any two numbers such as: d09.

I came up with the RegEx ^[a-z]{1}[0-9]{2}$ and ran it on the string

sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0

However, it never finds r30, the code below shows my approach in Java.

Pattern pattern = Pattern.compile("^[a-z]{1}[0-9]{2}$");
Matcher matcher = pattern.matcher("sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0");

if(matcher.matches())
    System.out.println(matcher.group(1));

it never prints out anything because matcher never finds the substring (when I run it through the debugger), what am I doing wrong?

  • 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-16T08:36:03+00:00Added an answer on June 16, 2026 at 8:36 am

    There are three errors:

    1. Your expression contains anchors. ^ matches only at the start of the string, and $ only matches at the end. So your regular expression will match "r30" but not "foo_r30_bar". You are searching for a substring so you should remove the anchors.

    2. The matches should be find.

    3. You don’t have a group 1 because you have no parentheses in your regular expression. Use group() instead of group(1).

    Try this:

    Pattern pattern = Pattern.compile("[a-z][0-9]{2}");
    Matcher matcher = pattern.matcher("sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0");
    
    if(matcher.find()) {
        System.out.println(matcher.group());    
    }
    

    ideone


    Matcher Documentation

    A matcher is created from a pattern by invoking the pattern’s matcher method. Once created, a matcher can be used to perform three different kinds of match operations:

    • The matches method attempts to match the entire input sequence against the pattern.
    • The lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.
    • The find method scans the input sequence looking for the next subsequence that matches the pattern.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i have this question i was trying to find a way to call
Hello I have one question about using genetic in correct way. please look at
I have very basic question about Flex SDK, but I didn't find any resources
I have a quick question about the two examples below. Currently I am using
Hello I am new to python and have a question about the best/pythonic way
I have a question about type casting. I have the following JSON String: {server:clients,method:whoIs,arguments:[hello]}
Hello everyone I have a question... I'm trying to make my sms faker app,
Hello i have a question about servlet calling another servlet I have a main
Hello i have some question about java. here is my code: public static void
Hello I have a pretty basic question about events in JS. Can I do

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.