This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Regular Expression pattern search is throwing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression pattern search is throwing "java.lang.IllegalStateException"" Watch "Regular Expression pattern search is throwing "java.lang.IllegalStateException"" New topic
Author

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

Poorav Chaudhari
Ranch Hand

Joined: Sep 17, 2002
Posts: 50
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



Poorav Chaudhari
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Sep 17, 2002
Posts: 50
I realized I needed to call the matcher.match() or the matcher.find() method before calling matcher.start().
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regular Expression pattern search is throwing "java.lang.IllegalStateException"
 
Similar Threads
Need to tokenize a String , but i need to keep what comes between "and"
Regular Expressions: A String should not contain the word "TEST"
regex
matcher find() problems
Pattern Matching