webmaster Posted October 28, 2009 Share Posted October 28, 2009 I have seen PHP regex backreferences done two ways on the web: one as \1, where it represents the first captured pair of parentheses, and $1 which is the same thing. Which is the correct way? Link to comment Share on other sites More sharing options...
Synook Posted October 28, 2009 Share Posted October 28, 2009 replacement may contain references of the form \\n or (since PHP 4.0.4) $n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n'th parenthesized pattern. n can be from 0 to 99, and \\0 or $0 refers to the text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern. To use backslash in replacement, it must be doubled ("\\\\" PHP string). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.