*
The moose likes Java in General and the fly likes Regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular expression " Watch "Regular expression " New topic
Author

Regular expression

yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
HI,

When I try to match a special character with the regular expression it hangs.

The code for regular expression matching is:
Pattern pattern=Pattern.compile("abc");
Matcher match=pattern.matcher("--------------");
if(match.find()){//it hangs here
}

With regards,

Yathish
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14195
    
  20

What do you mean by "it hangs"? Do you get an error message, or is the output different from what you expect? Or does the program lock up? I tried your code with a small test program:

It prints "Two", exactly as expected.

Please explain your problem more clearly.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
hi,
Regular expression locks up.And it fails to terminate and does not throw any error.Is there some means by which I can exit out when the java util hangs.

With regards,

Yathish
shank ram
Greenhorn

Joined: Sep 05, 2005
Posts: 22
Please, make your question clearer. State what you expect and how that does'nt happen?

As mentioned by Jesper the code seems to work perfectly.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by yathish Gatty:
hi,
Regular expression locks up.And it fails to terminate and does not throw any error.Is there some means by which I can exit out when the java util hangs.

With regards,

Yathish


As Jesper explained, the above code does not cause the program to "hang". Since Java has no control over whether your computer freezes or not, there is no way it can determine when to exit. Besides, if the computer is locked up, it wouldn't be able to execute the code to make your program exit anyway.

With that said, I suspect there is some other cause of your problem. Can you provide more details about what happens when you run this program. It will probably be helpful if you describe how you run the program (i.e. using an IDE or the command line).

Layne


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Also, you should add System.out.println() calls in order to find more about what is happening in your program.

Layne
 
GeeCON Prague 2014
 
subject: Regular expression