I can never seem to find any documentation on the regex for matching a capture group as part of the pattern. For example:
(\w\d\w):$1
..should match a4b:a4b
$1 doesn’t work, but I know it’s something similar. Anyone know?
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.
In a regex pattern, a backreference to the first capturing group is always
\1, not$1.Reason:
$means “end of string” (or end of line, depending on context) in a regex.In a replace pattern (which isn’t a regex), some dialects allow
$1(e. g. .NET, Java, Perl and JavaScript), some allow\1(Python and Ruby), and some allow both (PHP and JGSoft).Edit: Since you wrote that you couldn’t find any documentation on this, check out these overviews on regular-expressions.info: