How do you use back-references to PCREs in PHP?,
I read this but either I’m missing something, misreading something, or it doesn’t work the way they say. I’m guessing it’s one of the first two.
$str = preg_replace("([|]d*)", "1;", $str);
Your regular expression should follow Perl syntax, meaning it has to start and end with the same character (with some exceptions). Also, the back reference should start with a double slash, to get around PHPs double escaping. This should work (with a quick test):
$str = "asdfasdf |123123 asdf iakds |302 asdf |11"; $str = preg_replace("/([|]d*)/", "\1;", $str); echo $str; // prints "asdfasdf |123123; asdf iakds |302; asdf |11;"
That’s the answer How do you use back-references to PCREs in PHP?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you