My question uses a regex code example from S&B page 498 but is not about regex. S&B state that m.group() can return an "empty string" (page 508) so since (1) prints 0 why don't (2) and (3) give the same result ? Execute the code >javac GBTestR1X1 "d\*" ab34ef I have the feeling that it's somewhat obvious and should thank you for ypur replies with a blushing Graemlin (but there isn't one).
Well, for group() to return an empty string, your regex would need to allow empty strings to match, or so it seems to me. As far as I can tell, your's doesn't.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Graeme, such rudeness is not called for here. I would have answered your question much as Ilja did, and I still don't see how that does not help you. Ilja addressed a major reason why you're not seeing the same results from statements (2) and (3) as from (1): statements (2) and (3) never execute at all. Because find() returns false, because your regex never occurs anywhere inside the search string.
There are other reasons why these statements might give different behavior than what you're expecting, but I think that is the biggest one.
If that's not what you were trying to ask, I would suggest that try to politely rephrase your question.
Originally posted by Mike Simmons: Graeme, such rudeness is not called for here.
Thank you very much for stepping in, Mike.
You do not have a metacharacter which counts any number of occurrences. You have an asterisk, because you escaped it.
Joined: Apr 16, 2004
The "d\*" was a typo and should read "\d*".
A blushing gremlin (as I suggested this code might warrant , I really can't imagine what I was thinking) for the "==" String compare - that is what is actually causing the 'comparison failure' between an empty String and String length 0.
My sincere apologies to Ilja Preuss for my over harsh reaction to his attempt to assist with my problem. [ October 28, 2008: Message edited by: Graeme Byers ]