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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:31:30+00:00 2026-06-13T22:31:30+00:00

I have a regex containing something like ([A-Za-z]\s)+ . It returns one group containing

  • 0

I have a regex containing something like ([A-Za-z]\s)+. It returns one group containing all the letters followed by a space. However, it keeps only the last element in the group for example if the text contains a b c d, I tried to print the group match but it returns only the letter (d). This is my program

while (m.find()) {
      L = m.group(1);
      System.out.println(L);
                  }

My question is why I only get letter (d) instead of all letters? Is it because They are all captured through one group? how can I correct that? How can I iterate through one group. For example, iterate through all matches detected as one group?

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

    The problem with your regex is that it matches all sequences of one character followed by a space.

    In your example, group() would return the whole a b c d string. However when capturing braces are inside repetition (like your +), only the last captured value can be retrieved, hence group(1) returns d.

    To fix your issue, just remove the + from your regex. This will make the find() succeed several times, and each time you will get a different match. In that case you might even drop the parenthesis and simply use group().

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

Sidebar

Related Questions

I have a string containing something like this ... /\*start anythingCanBeEnteredHere end\*/ ... I
I have this regex that detects hashtags. It shouldn't match things with letters before
I have this regex /^([a-z0-9]([a-z0-9-]*[a-z0-9])*){1,60}\.cz$/i . Rules: Domain Name may contain only characters [a-z,0-9,-]
I have some Regex, it looks like this: string regexForDrop = @^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)$; It works
I have an input file something like this: some line some other line another
I have an HTML string containing multiple <image> tags. I'd like to search for
I have a large file that looks something like this: <Feed stack_overflow> sourceid 32456
I have two databases, both containing phone numbers. I need to find all instances
I have a JTable with four columns, the first one containing either a number
I have a file with a list of regex patterns and string containing '\n's'

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.