I have some issues understanding the logic implemented by the find()/start() methods in class Matcher .
I would have guessed that this code produced the output: 0123445 But it actually gives: 01234456 The last '6' is my concern here, why does it return the extra '6' in the end? For any output to be printed find() must return true, how can it return true for a value of start() being 6? It is outside the patternstring range?
Ok, so then my assumption that find() actually includes the terminating null character in its logic is correct? That was not what I would have expected from a find() implementation. A regex on an empty string (only a \0) I would have assumed returned 'false' since it has nothing to compare against! Tricky, really tricky! I would certainly have failed this question on the exam
Ok well, I believe an "empty" string is just a \0 in memory with a reference to it. If find() returns true on an empty string means it must have evaluated/included also the \0 as a valid source in its logic. So empty strings (\0) are handled as a special case.
Thanks for the link! That really explains it all!
[ September 25, 2006: Message edited by: Hans Beck�rus ] [ September 25, 2006: Message edited by: Hans Beck�rus ]