Kartik it
Kartik it

Reputation: 403

regular expression character followed by number php

I want to add backslashes to following string where u followed by number 0-9 with regular expression in PHP.

$string="u00fehehu2122k ru00f0ru00f0u00c4 ytu201ekuu2122e";  

i want this result after converted.

$result="\u00feheh\u2122k r\u00f0r\u00f0\u00c4 yt\u201eku\u2122e";  

i have write,

$string= preg_replace("/.u/", "\", $string);  

but is does allow me to add "\" in second parameter.
so is there any other way to do this.

Upvotes: 0

Views: 291

Answers (1)

falsetru
falsetru

Reputation: 368954

Using capturing group to capture digit part.

$string = preg_replace('/u(\d)/', "\\u$1", $string);

Upvotes: 1

Related Questions