Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression Doubt

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running the program on page 483 gives:


You have the 0, 3, 6 (start positions) correctly, where are your groups?
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sandeep Vaid:
I got it. It's the Matcher group() method which produces that output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic