• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Regex - Matcher class

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Above code works fine and prints test
start: 0 group: ab in the output.

But if I comment out the if condition i.e if( matcher.find()) then
I get Exception in thread "main" java.lang.IllegalStateException: No match available

Why is it so. I am confused.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. read the error message text.
2. read the API for Matcher.find(), Matcher.start(), and Matcher.group()

You should then immediately see the answer, I did.

Or you can wait until someone spoils it all by telling you the answer directly.
[ September 22, 2006: Message edited by: Barry Gaunt ]
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry I got it.

From API:

public int start()
Throws:
IllegalStateException - If no match has yet been attempted, or if the previous match operation failed


public String group()
Throws:
IllegalStateException - If no match has yet been attempted, or if the previous match operation failed
 
reply
    Bookmark Topic Watch Topic
  • New Topic