I am editing a Perl file, but I don’t understand this regexp comparison. Can someone please explain it to me?
if ($lines =~ m/(.*?):(.*?)$/g) { } ..
What happens here? $lines is a line from a text file.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Break it up into parts:
So, this will match strings like
":"(it matches zero characters, then a colon, then zero characters before the end of the line,$1and$2are empty strings), or"abc:"($1 = "abc",$2is an empty string), or"abc:def:ghi"($1 = "abc"and$2 = "def:ghi").And if you pass in a line that doesn’t match (it looks like this would be if the string does not contain a colon), then it won’t process the code that’s within the brackets. But if it does match, then the code within the brackets can use and process the special
$1and$2variables (at least, until the next regular expression shows up, if there is one within the brackets).