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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:43:09+00:00 2026-05-23T10:43:09+00:00

I modified the following code from Oracle’s Java Tutorials : import java.util.regex.Pattern; import java.util.regex.Matcher;

  • 0

I modified the following code from Oracle’s Java Tutorials:

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegexTestHarness {

public static void main(String[] args){

    while (true) {
        Pattern pattern = Pattern.compile("foo");
        Matcher matcher = pattern.matcher("foo foo foo");

        boolean found = false;
        while (matcher.find()) {
            System.out.format("I found the text \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end());
            found = true;
        }
        if(!found){
            System.out.format("No match found.%n");
        }
    }
}
}

I am trying to learn how to use regular expressions in Java. (I feel pretty confident about regex’s, just not with Java’s classes for using them.) I am using Eclipse, which I am also not incredibly familar with. I could not figure out how to get the console to not be initialized to null (as the tutorial warned), so I removed it and am just using static values and recompiling every time I want to try something new.

When I run this code, I get an infinite loop:

I found the text "foo" starting at index 0 and ending at index 3.
I found the text "foo" starting at index 4 and ending at index 7.
I found the text "foo" starting at index 8 and ending at index 11.
I found the text "foo" starting at index 0 and ending at index 3.

etc., etc., etc. until I hit terminate

What am I doing wrong?

Thanks.

Nevermind… >.< For some reason I didn’t see the infinite loop on the outside. I assumed the whole time that it was the other loop that was the problem.

  • 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-23T10:43:10+00:00Added an answer on May 23, 2026 at 10:43 am

    You currently have a while(true) arround that section of your code. while(true) is an infinite loop, and you never seem to break out of it.

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

Sidebar

Related Questions

I have the following code, which is a modified version from MSDN's website, to
I'm using the following code (which is a sample from the MSDN slightly modified)
I use comboboxes code taken from jquery examples . This is modified to use
I have the following code: ServiceSoapClient service = new ServiceSoapClient(); var dataSource = (from
When I run the following code: Public Function DeleteSessionItem(ByVal thisSessionItem As SessionItem) As Boolean
The following code is not displaying the image from IIS 6/PHP 5.2.9. It works
I am running the following code to try and read from a text file.
Code Taken From: Bytes to Binary in C Credit: BSchlinker The following code I
I created an assembly (dll) with the following classes: Person.cs [Table(People)] public class Person
I've modified my .htaccess file to have the following statement RewriteCond $1 !^index.php$ RewriteRule

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.