Sunday, August 2, 2009

What does /^\s*\.*?\s+\.*?\s+(.*?)\s+.*\... means in Perl Programming?

Can anyone kindly explain to me what does the following expression mean in PERL programming?





If (/^\s*\.*?\s+\.*?\s+(.*?)\s+.*\s*$/) {


print “$1\n”;


}

What does /^\s*\.*?\s+\.*?\s+(.*?)\s+.*\... means in Perl Programming?
It looks to me that it is PERL form of the HTML bold.
Reply:I don't know perl but I do know that what is being tested is a regular expresion. However it doesn't seem that the regular expression is being used, it looks like it's just being declared.





The regular expresion would match something like " .... ..... foo bar ", $1 would refer to "foo" in this case.
Reply:This is a regular expression - since it seems to be cut in the submission I cant fully understand it but - refer here


http://www.perl.com/doc/manual/html/pod/...
Reply:^ = beginning of line


\s* = zero or more whitespace characters (as many as possible)


\.*? = zero or more periods (as few as possible)


\s+ = 1 or more whitespace characters


\.*? = zero or more periods (as few as possible)


\s+ = 1 or more whitespace characters


(.*?) = zero or more of any character (as few as possible) (save this in $1)


\s+ = 1 or more whitespace characters


.* = zero or more of any character (as many as possible)


\s* = zero or more whitespace characters (as many as possible)


$ = end of line


No comments:

Post a Comment