• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Regular Expressions - Greedy Quantifiers

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the K&B book Certification Objective �Parsing,Tokenizing, and Formatting (Exam Objective 3.5):
it says: "The greedy quantifier does in fact read the entire source data, and then it works backwards (from the right) until it finds the rightmost match..."
and if we go to the first question in the related "Self Test" section with the command line: java Regex2 "\d*" ab34ef
which has the result : 01234456
and exactly(same result, but with more detail ):
0
1
2 34
4
5
6

Here! we are in a greedy situation and the source data has been read from the left to the right(based on the index!), which is contradictory to what is said in the K&B book concerning the greedy situation

any help there?
Thanks!
 
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
Have you seen our SCJP FAQ: Could someone explain the Regex2 class from K&B's Java 5 Study Guide?
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic