1

i was wondering if the issue is visible for you guys, i have searched many 'a stackoverflow post but have failed to get an answer.

I'm trying to make a matcher that will eventually match C.V's and Job openings. Now I'm starting to learn about regexes and matching using aforementioned regexes. I am trying to get a successful match to get the feel of matching to eventually match those other things I mentioned, but now even the simple stuff isn't working.

public class RunMatchSequence {

public static void main(String[] args) {
    try {



    String emailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
    //  String emailRegEx = "(?s).*";
    Pattern pattern = Pattern.compile(emailRegEx);

     String target= "You can email me at [email protected] or [email protected] to get more info";
     String target2="You can email";
    java.util.regex.Matcher matcher; {

     matcher = pattern.matcher(target);

     while(matcher.find()) {
         System.out.println("Found a Match" + Matcher.group());
         System.out.println("Start position: " + Matcher.start()); 
         System.out.println("End position: " + Matcher.end()); 
          }}} catch (StackOverflowError e) {
              System.out.println("Stackoverflow");
                //JOptionPane.showMessageDialog(null, "Stackoverflow");
            }
}

}

This being the class that runs the pattern. what follows is the class that holds the group, this is where the StackOverflowError occurs.(thinking its something to do with infinite recursion, but I have no idea how to solve it): EDIT: I now realize what caused the infinite recursion is the return statement, but i have no idea what to put there

public class Matcher{
 public static void main(String[] args) {

     RunMatchSequence.main(args);

//implements MatchResult {
 //  Pattern p = Pattern.compile("a*b");
 //   java.util.regex.Matcher m = p.matcher("aaaaab");
// boolean b = m.matches();
//}
     }

static String group() {
// TODO Auto-generated method stub
return group();
}

static int end() {
// TODO Auto-generated method stub
return end();
}

static int start() {
// TODO Auto-generated method stub
return start();
}

}
6
  • What are group(), end(), and start() supposed to be doing? You are correct that they result in infinite recursion. But what values are they supposed to be returning? Commented Dec 16, 2013 at 13:26
  • the matched value. the end start show the location in the string. Commented Dec 16, 2013 at 13:27
  • Ah, okay. Well I don't know much about regex objects, so I can't give you an answer about how to get those values, but searching for it should get you an answer. I would definitely just remove the return group()/end()/start(); lines though. You're not going to get anywhere with them. Commented Dec 16, 2013 at 13:30
  • 1
    well it turns out.... that the java library supports the matcher/pattern api and all you need to do is call matcher.group() in the printline..... and that my mistake was writing matcher.group() with a capital M which is not recognized by the API. Commented Dec 16, 2013 at 14:14
  • 1
    @user2674895: Please post your solution as an answer and mark it as an answer. Thanks :) Commented Dec 28, 2013 at 14:37

2 Answers 2

2

When you call Matcher.group, it crashes because the group method is recursive, but with no condition to avoid infinite calls.So the method is called and called and called...

Sign up to request clarification or add additional context in comments.

Comments

1

well it turns out.... that the java library supports the matcher/pattern api and all you need to do is call matcher.group() in the printline..... and that my mistake was writing matcher.group() with a capital M which is not recognized by the API.

so these:

    static String group() {
    // TODO Auto-generated method stub
    return group();
    }

    static int end() {
    // TODO Auto-generated method stub
    return end();
    }

    static int start() {
    // TODO Auto-generated method stub
    return start();
   }

are obsolete.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.