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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:29:36+00:00 2026-05-25T13:29:36+00:00

I am trying to obtain the string that my matcher is able to find

  • 0

I am trying to obtain the string that my matcher is able to find using my provided expression. Something like this..

if(matcher.find())
    System.out.println("Matched string is: " + ?);

What would be the appropriate code for this? According to Oracle the

matcher.group();

method returns only the provided input same as

matcher.group(0);

Thanks in advance..

Edit:

Example follows below:

private static String fileExtensionPattern = ".*<input type=\"hidden\" name=\".*\" value=\".*\" />.*";
private static Matcher fileXtensionMatcher;
private static String input = text  "<html><body><table width="96"><tr><td><img src=&quot;file:/test&quot;  /><input type="hidden" name="docExt" value=".doc" />Employee Trv Log 2011 Training Trip.doc</td></tr></table></body></html>"

private static void findFileExtension() {
    System.out.println("** Searching for file extension **");
    System.out.println("Looking for pattern: " + fileExtensionPattern);
    fileXtensionMatcher = fileXtensionExp.matcher(input);

    if(fileXtensionMatcher.find()) {
        //the extension expression is contained in the string
        System.out.println("Extension expression found.");
        System.out.println(fileXtensionMatcher.group());
    }
}

The obtained result is:

text    "<html><body><table width="96"><tr><td><img src=&quot;file:/test&quot;  /><input type="hidden" name="docExt" value=".doc" />Employee Trv Log 2011 Training Trip.doc</td></tr></table></body></html>"
  • 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-05-25T13:29:37+00:00Added an answer on May 25, 2026 at 1:29 pm

    After you added the source code, I can assure you the group() returns the whole input string because it matches your regular expression. If you want just the <input> element use:

    private static String fileExtensionPattern = "<input type=\"hidden\" name=\".*\" value=\".*\" />";
    

    Or use:

    private static String fileExtensionPattern = ".*(<input type=\"hidden\" name=\".*\" value=\".*\" />).*";
    . . .
    System.out.println(fileXtensionMatcher.group(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how could I parse this string using sstream and
I'm trying to find a MySQL query which will obtain the time that is
I'm using boost::regex_match and I'm trying to find a function to obtain the position
I'm trying to obtain the correct unicode characters represented by this string: string originalString
I'm trying to obtain the machine precision on gmp variables. To that end, I
I am trying to obtain the value part of this syntax: [name:value] I got
I'm using Hibernate and JPA for a small project. Somehow when trying to obtain
Suppose I was trying to match the following expression using regex.h in C++, and
I'm trying to find the positions of all occurrences of a string in another
i am trying to obtain an item from a collection that occurs most frequently.

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.