wood burning stoves 2.0*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 390
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: 390
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: 390
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: 390
Originally posted by Sandeep Vaid:
I got it. It's the Matcher group() method which produces that output.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regular Expression Doubt
 
Similar Threads
Jtable and Scrollbar
how it works
doubt regarding pattern matching in java
Conversion of Array into List
i cant ...... learn to use the split