The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes pattern matching Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "pattern matching " Watch "pattern matching " New topic
Author

pattern matching

vineet walia
Ranch Hand

Joined: Feb 16, 2008
Posts: 137


its output is:
0
1
2
3
5
6
7
8
9
10
11
13
14
15

2nd code is:


its output is:
3
6
11
* will match 0 or more times
please explain difference in output
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 270

First one is using "a*" which means 0 or more occurences of a. So it checks each and every character from 0 to length().
Second one is "aa*, which means "a" and THEN "a*". First there has to be "a" and then 0 or more occurences of "a". There are only 3 cases like that, hense the output is like that!

Hope this helps!


SCJP6, SCWCD5, OCPJBCD5, OCEJWSD6 [Work in progress - OCEJPAD6] , [ Work in Progress- OCMJEA5] - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
vineet walia
Ranch Hand

Joined: Feb 16, 2008
Posts: 137
thank you so much brother
vineet walia
Ranch Hand

Joined: Feb 16, 2008
Posts: 137
one more thing in first case
"oblaada oblaadi"
15 character

so why its is starting at 0 and end at 15(it should be at 14)?
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 270

vineet walia wrote:one more thing in first case
"oblaada oblaadi"
15 character

so why its is starting at 0 and end at 15(it should be at 14)?

You are welcome mate!
This is a special case with the '*' meta character, and it always look after the last character! Please go through the K&B book chapter for Patterns and Regex.

Wish you all the best!

 
 
subject: pattern matching
 
MyEclipse, The Clear Choice