| Author |
problems with regex
|
susana miranda
Greenhorn
Joined: May 21, 2008
Posts: 9
|
|
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
|
 |
Harpreet Singh janda
Ranch Hand
Joined: Jan 14, 2010
Posts: 317
|
|
Please use code tag to post the code like
|
 |
Harpreet Singh janda
Ranch Hand
Joined: Jan 14, 2010
Posts: 317
|
|
* means 0 or more
So it will consider each element of line as eligible.
|
 |
susana miranda
Greenhorn
Joined: May 21, 2008
Posts: 9
|
|
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
Joined: Jan 14, 2010
Posts: 317
|
|
|
Yes, as you know * means 0 or more and after 90 there is nothing so it will be counted.
|
 |
susana miranda
Greenhorn
Joined: May 21, 2008
Posts: 9
|
|
|
Ok, thanks a lot.
|
 |
 |
|
|
subject: problems with regex
|
|
|