This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is a example for SCJP for Java Platform, SE6 STUDY GUIDE by Richard F. Raposa and can be found at page 317.
In the books is write
The pattern matches any word that starts with any character between ‘ q ’ and ‘ v ’ (the [qrstuv] ) repeated any number of times (the “ * ” ), followed by any single character (the . ), and ending with the literal string “ ing ” . Using the tests array from the previous examples, the matches are
ring matches [qrstuv]*.ing
trying matches [qrstuv]*.ing
In my compilatin, the return was:
ing matches [qrstuv]*.*ing
ring matches [qrstuv]*.*ing
trying matches [qrstuv]*.*ing
running matches [qrstuv]*.*ing
"*" does mean "repeated any number of times" including zero times. So, for the other two cases, where the word doesn't start with "q" to "v", the regex engine matches it zero times. This allows the "." to match the first character instead.