Thanks Jim Now i understood completely. Very good explanation.
On Fri, May 27, 2011 at 10:45 AM, Jim Gibson <jimsgib...@gmail.com> wrote: > At 10:28 AM +0530 5/27/11, vishesh kumar wrote: > >> Hi Jim >> > > 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. > > -- http://linuxmantra.com