This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regular Expression Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regular Expression Doubt" Watch "Regular Expression Doubt" New topic
Author

Regular Expression Doubt

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
source : "1 a12 234 b"
pattern: \d+

It prodces the output as 036 but in Kathy Seria's book (P-477) it's written that it produces

0 1
3 12
6 234
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Running the program on page 483 gives:


You have the 0, 3, 6 (start positions) correctly, where are your groups?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
On Page 483, the pattern is /d/w and not /d+.

My Question is :

On page 477, using /d+ as pattern he produces the output as

0 1
3 12
6 234


is that incorrect ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
As I wrote,running the program on 487 with source : "1 a12 234 b"
pattern: \d+
produces
0 1
3 12
6 234
[ October 02, 2006: Message edited by: Barry Gaunt ]
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
I got it. It's the Matcher group() method which produces that output.

Then surely there is a mistake in kathy's book on p - 477....
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
Originally posted by Sandeep Vaid:
I got it. It's the Matcher group() method which produces that output.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression Doubt