| 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
Bartender
Joined: Aug 16, 2005
Posts: 12950
|
|
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 7 API documentation
Scala Notes - My blog about Scala
|
 |
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
|
 |
 |
|
|
subject: Regular expression
|
|
|