I'd be happy to lend a hand (as I am sure others would be), but could you please post your complete code snippet rather than pseudo code. As posted right now, it looks like the code is using some method pattern() that takes a string. There is no such method in the Java API anywhere. So I have no idea what the code is doing there. And I can only assume the find() method and start() methods in the code are the find() method from the Matcher class... but that's a big assumption.
Please see the FAQ tip PostRealCode for more info.
This thread is much more confusing than it needs to be. Dash's pseudocode implies that he's matching the regex "aaaaa" against the target string "a*", which is backward. Then we learn from the the quoted text in Marilyn's reply (quoted from where, I wonder? - edit: never mind, it came from here) that the regex is really "a?", which is good, because "a*" is inconsistent with the output. Dash, this is why you should post your real code whenever possible, as Mark suggested.
Anyway, Rob's answer is still essentially correct despite the changed regex. Here's a complete demonstration: output: As you can see, each match starts where the previous one ended. Since the regex can match zero characters, it matches the empty string starting at index 5. [ July 20, 2008: Message edited by: Alan Moore ]
Dash Abhisek
Ranch Hand
Joined: Jul 20, 2008
Posts: 63
posted
0
Thanks Alan for demonstrating the answer but In the String I have given five a so the first a is at position 0 and the fifth a is position at 4th position then how come 5th index is there ?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
Please read the replies, particularly Rob Prime's which explains it simply.
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
posted
0
Originally posted by Dash Abhisek: Thanks Alan for demonstrating the answer but In the String I have given five a so the first a is at position 0 and the fifth a is position at 4th position then how come 5th index is there ?
The regex "a?" in combination with the string "aaaaa" will match on the following places:
Dash Abhisek
Ranch Hand
Joined: Jul 20, 2008
Posts: 63
posted
0
Thanks to Everybody who gave Reply
My doubt is cleared
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.