aspose file tools*
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
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().
 
I agree. Here's the link: http://aspose.com/file-tools
 
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"
Pattern Matching
regex
Regular Expressions: A String should not contain the word "TEST"
matcher find() problems