PHP preg_replace - using [ ] generates warnings

52 views Asked by At

Can someone give me a hand with the following

$file = preg_replace("/([^\\])([\\])([^\\rnt])/", "$1$2$2$3", $file);

When i run this i get the following warning: "Warning: preg_replace(): Compilation failed: missing terminating ]"

I want to replace in a string all single \ with double \ if there is no r n or t after it. so \r \n \t should remain as they are. \ also should remain as it is but xx\2 should become xx\2

string example: "lorem ips\um do\\lor s\it amet \r \n 34\3" should become "lorem ips\\um do\\lor s\\it amet \r \n 34\\3"

Thank in advanced

1

There are 1 answers

0
SeinopSys On

Change double quotes to single quotes:

$file = preg_replace('/([^\\])([\\])([^\\rnt])/', "$1$2$2$3", $file);