Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression pattern search is throwing "java.lang.IllegalStateException"

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to find the position of string that matches the regular expression in a given 'word'. But for some reason I get the following Exception.

Exception in thread "main" java.lang.IllegalStateException: No match available
at java.util.regex.Matcher.start(Matcher.java:325)
at myworkspace.TestRegEx.<init>(TestRegEx.java:16)
at myworkspace.TestRegEx.main(TestRegEx.java:21)

I have created a small program that demonstrates the problem, posted below. I would really appreciate some input on this. thanks

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have better luck if you post your actual code, so that the line numbers in the exception line up with the line numbers posted.

This may mean you'll have to create a separate, smaller program just to demonstrate the problem.


Also, have you tried looking at the docs for Matcher.start(), to understand how to use it correctly, and to see why it might throw that exception? That's generally the best place to start.

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realized I needed to call the matcher.match() or the matcher.find() method before calling matcher.start().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic