$line = " TEST: asdas :asd asdasad s";
if ($line =~ /(.*):(.*)/
{
print "$1 = $2 "
}
I was expecting TEST =asdas :asd asdasad s
But it’s not working. What is issue?
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.
The correct way would be:
or
This way, you’re not matching “anything” on the left. You’re matching “one or more non-colon characters” in the first example, or “matching the shortest possible string of any characters followed by a colon” in the second.
The even better way is to not use a regex. Use
split.The
,2says “I want at most two fields”.