aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pattern Matching 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 "Pattern Matching" Watch "Pattern Matching" New topic
Author

Pattern Matching

harmeet saini
Ranch Hand

Joined: Apr 11, 2010
Posts: 33
Hi
Follwing is a question from K&B chapter 6 Self Test

And the command line :

java Regex2 "\d*" ab34ef

Answer given is 01234456

When I ran this program I am not getting any output, I am not able to understand why this is happening. Please help

Thanks

Regards,
Harmeet Singh
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Check this faq...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
harmeet saini
Ranch Hand

Joined: Apr 11, 2010
Posts: 33
Thanks ankit for sharing the link, however i have two doubts

1) why my machine is not giving me any output for pattern "\d*" althought playing with it like "\d+" od "\d" is giving me output
2) as per the docs i am not able to understand the index of each character in the string, means does the character "a" is at index 0 or at 1

Thanks in advance
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Oops I didn't see that you were having problems with getting an output. Are you running the program from command line or some IDE?? Also make sure to include the "" around \d* as * has special meaning for windows command line.
For the index of a, its 0...
harmeet saini
Ranch Hand

Joined: Apr 11, 2010
Posts: 33
i am running the program from command line and have used "" around \d* still its not giving me the output, is it like this expression gives different output for different JVM's , althought i don't find any reason for this

for my 2nd doubt ,so it means the expression "\d*" find a expression of zero length after the string "ab34ef" that is at index 6 ? although the last index is 5(i.e "f").

Thanks in advance
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

harmeet saini wrote:so it means the expression "\d*" find a expression of zero length after the string "ab34ef" that is at index 6 ? although the last index is 5(i.e "f").

Well there will be a zero length match *after* f which is the index 6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pattern Matching