|| at May 27, 2011 at 5:15 am
At 10:28 AM +0530 5/27/11, vishesh kumar wrote:
You should address all of your questions to the list as a whole. That
way you will get smarter people than me helping you.
echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/'
Giving desired result, but i wonder what is use of ? in this expression
Did you try it without the question mark? If you do, you will see the
affect of "greedy" quantifiers. Without the question mark, the first
'.*' matches the longest string. This means that you won't get the
full IP address, just the minimal part at its rear end that matches
the '\d+\.[\d.]+' part, which could be '1.1' for example. With the
'?', the initial '.*' matches only the part of the string before the
first digit, and the whole IP address is matched and captured.