What is the difference between php reverse reference 1 and $1? Php regular expression. someone will see it using \ 1.
Use $1 later
What are the differences between the two? Which one is generally used?
Reply to discussion (solution)
The rule string can only be shown as \ 1
Because $ indicates the end of a row, \ $1 is prone to ambiguity.
For later use, there is no difference
Perl uses $1 to access the matching group.
In the regular expression, only \ 1 can be used, and in the replacement string, both can be used.
Preg_replace can contain the backward reference \ n or (php 4.0.4 or above) $ n, which is preferred in syntax. Each such reference replaces the text captured by the nth capturing sub-group that is matched. N can be 0-99, \ 0 and $0 represent the complete pattern matching text. The serial number counting method of the captured sub-group is as follows: left parentheses of the captured sub-group start from left to right and start from 1. To use a backslash in replacement, you must use four, after the regular expression engine is used, it is considered as a backslash of the original article ).
When it works in the replacement mode and the back reference is followed by another number (for example, adding an original number after a matching mode ), you cannot use a syntax like \ 1 to describe backward references. For example, \ 11 will make preg_replace () unable to understand what you want is a \ 1 back reference followed by an original article 1, or a \ 11 post is not followed by anything. In this case, the solution is \ $ {1} 1. This creates an independent $1 back reference and an independent original 1.
Reference from php manual preg_replace