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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:07:20+00:00 2026-06-09T16:07:20+00:00

Possible duplicate: Print regex matches in java I am using Matcher class in java

  • 0

Possible duplicate: Print regex matches in java

I am using Matcher class in java to match a string with a particular regular expression which I converted into a Pattern using the Pattern class. I know my regex works because when I do Matcher.find(), I am getting true values where I am supposed to. But I want to print out the stings that are producing those true values (meaning print out the strings that match my regex) and I don’t see a method in the matcher class to achieve that. Please do let me know if anyone has encountered such a problem before. I apologize as this question is fairly rudimentary but I am fairly new to regex and hence am still finding my way around the regex world.

  • 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-09T16:07:21+00:00Added an answer on June 9, 2026 at 4:07 pm

    Assuming mis your matcher:

    m.group() will return the matched string.

    [EDIT] Added info regarding matched groups

    Also, if your regex has portions inside parenthesis, m.group(n) will return the string that matches the nth group inside parenthesis;

    Pattern p = Pattern.compile("mary (.*) bob");
    Matcher m = p.matcher("since that day mary loves bob");
    

    m.group() returns “mary loves bob”.
    m.group(1) return “loves”.

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

Sidebar

Related Questions

Possible Duplicate: Comparing Two Arrays Using Perl How can I print values which exist
Possible Duplicate: Correct format specifier to print pointer (address)? When printing a pointer using
Possible Duplicate: Is it possible to print out the size of a C++ class
Possible Duplicate: How should I print types like off_t and size_t? I'm using fstat(stream,
Possible Duplicate: Print preview ZPL II commands using .NET WinForm before sending it to
Possible Duplicate: RegEx match open tags except XHTML self-contained tags Hello first of I
Possible Duplicate: Print in terminal with colors using python? Just curious So I want
Possible Duplicate: JSON pretty print using JavaScript I'm working on a project that will
Possible Duplicate: Weird Java Boxing Hi, Can somebody explain why the last print returns
Possible Duplicate: Java exception handling In Java, is it possible to print in console

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.