This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Given the following regex pattern: "(?:\\D*(\\d+)\\D*)*"
and the following test cases: "12345" "a1234" "12a34" "1234a"
I expect to see each test case result in a set of groups that maintain the original character order, and exclude any non-digit characters.
My fallback is to iterate through the string char-by-char and build a new string skipping over non-numeric characters, but I am curious why this doesn't work for "12a34". In stead of returning the three groups "12a34" "12" "34", it returns "12a34" "34".
I use a tool called RegExCoach that can step through the groups and highlight them one at a time. You can interactively tweak your expressions and see how they respond. See it here: http://www.weitz.de/regex-coach/ This kind of experimentation is a fun way to learn.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi