How about if you post how you think this works (or how it fails to work according to your understanding)? Explaining something is a great way to make sure you really understand it. It's also the approach we prefer here at JavaRanch.
Hi Ashish, you have entered Exp "\d\w" "ab4 56_7ab"
The start() method returns the index of the matching pattern in your input string & group() method groups the matching pattern starting from the index position returned by start() method.
\d -search for a digit in the pattern \w search for a word in the pattern,a word can be digit,letter or "_"
your output is:
4 56 (your first matching statrs from index 4,that is 5 and second match is 6(digit,letter,"_")) 7 7a (second match starts from index 7,that is 7 and second match is a(digit,letter,"_"))
you might be confuse with the underscore,here underscore is not in the result because the 6 just before underscore is already matched & is not included in the next matching.If you insert a new digit before underscore then you will surely get underscore in the result.
I hope i have provided your answer,if there is any confusion then reply me
Originally posted by Jyothsana: As I see that the digit is starting from 2 the output should start from index no 2.
search string : "ab4 56_7ab" pattern : "\d\w" The pattern implies consecutive occurrence of a (digit)+(digit,letter,_)
Digit starts at index no.2 but the following character is a *space*, hence it does not match the pattern. Moreover "6_" also matchs the pattern, but since "6" has already been used in the match "56" hence "6" does not qualify to give a match of "6_".
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, that will fit in a stocking