| Author |
Regex Question with * quantifier from K&B
|
Raj Purushotham
Greenhorn
Joined: Apr 15, 2007
Posts: 2
|
|
Hi,
I am not clear on the Regex question (page 508 Question 1) from K&B 5 book
To uderstad I tried writing a similar program.
Lets say I give the followig commad line Java Regex "\d*" a
I get
0space
1space
I see that it is searchig for digits ad it finds 0 matches first time and prints postion 0 (search index 0). Then because we said * the start method returns to the previous index 0 now how come it goes to the postion 1 when there is only 1 charecter in the search strig.
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
UseCodeTags when you post a code. Please Edit it and put code tags. Welcome to JavaRanch!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
OK, What would happen you put + instead of *?
* - zero or more times
+ - one or more times.
Got it?
|
 |
Raj Purushotham
Greenhorn
Joined: Apr 15, 2007
Posts: 2
|
|
Hi Abimaran,
Thank you for the respose. I tried with + istead of * and the results are same.
I can see that if I use "\d?" for the source a23a12 it gives me what I suspect
1space23
4space12
How ever if I use "\d*" for the source a23a12 it gives me the following:
0space
1space23
3space
4space12
6space
"6space" is not clear to me.
|
 |
 |
|
|
subject: Regex Question with * quantifier from K&B
|
|
|