I’ve been looking at this code and it’s supposed to match my $input string and in $matches[0] store ‘testing’
$input = ':testing';
$r = preg_match('/^(?<=\:).+/',$input,$matches);
What’s wrong with it?
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.
(?<=)is a positive look-behind, which means that the text matching the enclosed expression must occur before the position of the parenthetical in the pattern. In this case, it means it must occur after the start-of-string position (^), but before the first actual character (.+matches all of the characters in the string here), and since the:is the first actual character, and there’s no:before the:(obviously), it fails to match.Instead, what you probably want to do is use a capture group, like so:
Thus you use
$matches[1]to get the text from within the capture group, which is what you want.