• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems with regex

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody! this is my first post
and... I have this class



I understand the result of my first execution:

% /SCJP/exercises$ java Regex
Pattern: \d+
Source: 123a456b78ccc0
start: 0 ---group: 123
start: 4 ---group: 456
start: 8 ---group: 78
start: 13 ---group: 0

but not the second

% /SCJP/exercises$ java Regex
Pattern: \d*
Source: 123a456b78ccc90
start: 0 ---group: 123
start: 3 ---group:
start: 4 ---group: 456
start: 7 ---group:
start: 8 ---group: 78
start: 10 ---group:
start: 11 ---group:
start: 12 ---group:
start: 13 ---group: 90
start: 15 ---group:

Why with \d* it returns an empty group if with \d i mean only numbers. I am a little confused :s

 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tag to post the code like


 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
* means 0 or more

So it will consider each element of line as eligible.
 
susana miranda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Harpreet. Thanks a lot. I had misunderstood * Only one more question:
Why on the second execution returns position start: 15? If my source ends with 90. Is it because null counts or so?

% /SCJP/exercises$ java Regex
Pattern: \d*
Source: 123a456b78ccc90
start: 0 ---group: 123
start: 3 ---group:
start: 4 ---group: 456
start: 7 ---group:
start: 8 ---group: 78
start: 10 ---group:
start: 11 ---group:
start: 12 ---group:
start: 13 ---group: 90
start: 15 ---group:

 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, as you know * means 0 or more and after 90 there is nothing so it will be counted.
 
susana miranda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks a lot.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic