• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Regular expression

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you should add System.out.println() calls in order to find more about what is happening in your program.

Layne
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic