Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

RegEx

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a question about RegEx. The following question is from Examulator mock-up,



I do not understand how o/p is obtained as rapraprerap. Can anybody shed some light on this. Thanks.
 
author
Posts: 23949
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Venkat Sidh:
Have a question about RegEx. The following question is from Examulator mock-up,



I do not understand how o/p is obtained as rapraprerap. Can anybody shed some light on this. Thanks.




The regular expression pattern is a letter "r", followed by a required word character, followed by an optional letter "p". The pattern will match 4 times...

  • "rap" from the first word
  • "rap" from the beginning of the second word "rapture"
  • "re" from the end of second word
  • "rap" from the end of the third word "wrap"


  • Henry
     
    Venkat Sidh
    Ranch Hand
    Posts: 61
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Henry,

    Thanks for explanatory answer.

    The regular expression pattern is a letter "r", followed by a required word character, followed by an optional letter "p". The pattern will match 4 times...



    Actually I'm confused about ? in expression, does ? (greedy quantifier) denote zero or one instance of character p?
     
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Venkat Sidh:
    ...Actually I'm confused about ? in expression, does ? (greedy quantifier) denote zero or one instance of character p?


    Yes, this is why it's matching "re" from the end of the second word.
  • r matches r
  • \\w matches the "word character" e
  • p? matches zero occurrences of p
  • So the match here is just re.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic