Issue with regular expressions in java

I keep getting the following exception when i try to do a regex search in java:

java.lang.IllegalStateException: No match available
        at java.util.regex.Matcher.end(
        at com.roeschter.jsl.DataGrab.get_value(

Here's my code:

String strOpenTableRegex = "<table";
returned_content = "xxxxxxxxxxxxxxxxxx<table>XXXXXXXXXXXXXXXXXXXXXX";
tables = 1;
for (int i=0;i<tables;i++)
      System.out.println("Compiling regex.");
      pattern = Pattern.compile(strOpenTableRegex);
      System.out.println("Matching regex.");
      matcher = pattern.matcher(returned_content);
      nCurOffset = matcher.end() + 1;

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This means that there is no match - check of there is one before you do the offset.
Simply use

boolean matchFound = matcher.matches();
if (matchFound ){
    nCurOffset = matcher.end() + 1;

If you want the above to match you need .*<table.* as a pattern. Or something like this - because at the moment the string does not match your pattern

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
opikeAuthor Commented:
I treid .*<table.*  (dot asterisk <table dot asterisk) and that didn't work with my code either.

I even simplified my example down to "table" (without the qutoes) which theoretically should work since it has no special characters, just literals. No dice.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

opikeAuthor Commented:
I figured out the problem... I was missing a matcher.find() call.
opikeAuthor Commented:
Awarding the points because of the effort to help.
I'd also move the Pattern.compile() call outside of your for loop.  There's no reason to do an expensive recompile for every line, the call to pattern.matcher() is all you need.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.