in reply to Look Ahead:

Because lookaheads are "zero length" matches. That is they do not consume any of the string that they match. So, in your example,

1welcometo india. ^...............is matched and consumed by ([0-9]+) ^^^^^^^........is matched but not consumed by (?=welcome) ^..............so "to india" tries to match here and fails.

This does match though:

$str = '1welcometo india';; $str =~ m/([0-9]+)(?=welcome)welcometo india/ and print 'matched';; matched

It's called 'lookahead' because it looks ahead but doesn't travel there.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^2: Look Ahead:
by nvivek (Vicar) on Apr 02, 2010 at 11:20 UTC
    Yeah,Thank you very much.I learnt about it and I also learnt about look behind operator in the regular expression.