aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex Question with * quantifier from K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Question with * quantifier from K&B" Watch "Regex Question with * quantifier from K&B" New topic
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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex Question with * quantifier from K&B
 
Similar Threads
Regex
quantifier
Doubt about Regex and Quantifiers
BinarySearch() Question
Tokenizing with regex pattern. Little confused!