At 10:28 AM +0530 5/27/11, vishesh kumar wrote:
Hi Jim
Hi Jim
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 theGiving desired result, but i wonder what is use of ? in this expression
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.