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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:14:14+00:00 2026-06-15T01:14:14+00:00

I tried this example just interchanging two lines it gives different outputs why String

  • 0

I tried this example just interchanging two lines it gives different outputs why

String inputString = "username@gmail.com"; 
String pattern="([a-z]+@)([a-z]+)(\\.[a-z]+)";
Pattern p = Pattern.compile(pattern); 
Matcher m = p.matcher(inputString); 

///changes happens here

if(m.find()) 
{
   String resultString = m.replaceAll("$1xxxx$3"); 
   System.out.println(resultString); 
}

System.out.println(m.matches());//line to be changed

output :

username@xxxx.com

true

System.out.println(m.matches());//line changed     
if(m.find()) 
{
   String resultString = m.replaceAll("$1xxxx$3"); 
   System.out.println(resultString); 
}

output :
true

  • 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-15T01:14:16+00:00Added an answer on June 15, 2026 at 1:14 am

    Extracted from Matcher.find documentation

    find

    public boolean find()

    Attempts to find the next subsequence of the
    input sequence that matches the pattern. This method starts at the
    beginning of this matcher’s region, or, if a previous invocation of
    the method was successful and the matcher has not since been reset, at
    the first character not matched by the previous match
    .

    If the match succeeds then more information can be obtained via the
    start, end, and group methods.

    Returns: true if, and only if, a subsequence of the input sequence
    matches this matcher’s pattern

    So, since you called Matcher.matches which attempts to match the whole String, and you did not reset the matcher, it tried to find starting after the first match. As there is only one match, it does not find anything.

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

Sidebar

Related Questions

Input: $string = this-is-just-an--example Output: this is just an-example Tried various things centered around
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
I just started with the connectivity and tried this example. I have installed the
I just tried to get this example code to run in my site. I
I tried this example in Perl. Can someone explain why is it true? if
I've tried this example directly from MSDN: Dim Screens() As System.Windows.Forms.Screens and I can't
I've tried implementing this example , but the progress never displays. My page doesn't
I am trying the GeoLocation feature in HTML5. I have tried this for example:
I tried to implement this example to write and read data from internal storage,
I tried to copy this example from this Multiprocessing lecture by jesse noller (as

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.