开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜