Time and time again I see $1 and $2 being used in code. What does it mean? Can you please include examples?
Share
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.
When you create a regular expression you have the option of capturing portions of the match and saving them as placeholders. They are numbered starting at
$1.For instance:
This will capture from
A90B3Cthe values90and3. If you need to group things but don’t want to capture them, use the(?:...)version instead of(...).The numbers start from left to right in the order the brackets are open. That means:
Matching against the same string will capture
90B,90and3.