• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pattern matching

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much brother
 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic