How can I solve regular expression reverse references in php? This post was last edited by u010572351 from 2013-06-0617: 46: 46. the regular expression is used to add a bracket to the four consecutive numbers, and the numbers remain unchanged. What the teacher said is reverse capture. it seems that {1} is used. I tried it and couldn't do it. what I said on the Internet is \ 1. is there a reaction, but it doesn't solve the regular expression reverse reference in php?
This post was last edited by u010572351 at 17:46:46 on. The regular expression is used to add a bracket to the four consecutive digits of the match, and the number remains unchanged.
What the teacher said is reverse capture. it seems that {1} is used. I tried it and couldn't do it. what I said online is \ 1. the response was correct, then I changed the \ 0 written below and captured it in reverse direction. but I checked it online. it seems that I did not write it like this ,,,,, but I did capture four numbers. why ??? Also, what does array-based regular expressions mean?
$ A = "abcd1234reo5678 ";
// Below we use the regular expression in php to process the above content
$ Myreg = array (
"/(\ D) {4}/I"
);
$ Con = array (
'[\ 0]' // capture the number. if you do not change it, add a bracket directly. I will write it myself.
);
Share:
------ Solution --------------------
$ S = 'wqe2313jyu6y6546iuoi ';
$ S = preg_replace ('/(\ d {4})/', '{$ {1}', $ s );
Print ($ s );
?>
Running result:
Wqe {2313} jyu6y {6546} iuoi
------ Solution --------------------
/(\ D {4 })/
[$1]
The number referenced in the reverse direction indicates the number of pairs of parentheses in the regular expression from left to right. Note (?...) Not included
Used only when there is ambiguity {}
For example, if you need to add a number after the reverse reference, it will produce ambiguity. you need to write $ {1} 1 -- to indicate the reverse reference of the first pair of parentheses, followed by the number 1
However, $11 references the content of the 11th pair of parentheses in reverse direction (if there are not so many parentheses, it is null)
------ Solution --------------------
/((? : 123) 456 (789 ))/
$1 get 123456789
$2 get 789