• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pattern matching

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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic