can you explain this regular expression.
$price = "...555.55";
$price = preg_replace('/^./', '', $price);
output:
$price = ..555.55;
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 regex
'/^./'matches any character at the beginning of the string.dot(.)matches any character except thenewlinecharacter, andcaret(^)is used to match at the beginning.So, your
preg_replaceis replacing any character at the beginning with an empty string.So,
...555.55becomes..555.55after replacing the first..If you just want to replace all the
dots(.)from the beginning, then you have to escape the.in your regex. Since simply using.will match any character. Also, you need to use some quantifier –*or+to replace moredots(.).So, your regex would be:
or: