PHP regex to find non-espaced letters
I want to replace F but not \F.
I've tried the following code, without any luck.
preg_replace("/[^\\]F/", "f", $str开发者_StackOverflow社区);
Try this :
preg_replace("/(?<!\\\)F/", "f", $str);
This works.
$string = preg_replace('/([^\\\]|^)F/', '$1f', $string);
The reason there are three backslashes, is because the first one escapes the second one for the string, and that one escapes the last one for the regex. Here's a topic on another site about it: http://forums.devnetwork.net/viewtopic.php?t=125752
Update: Thanks to @Damp and @webbiedave
精彩评论