php regex is not escaped
what is a regex to find any text that has 'abc' but does no开发者_如何学运维t have a '\' before it. so it should match 'jfdgabc' but not 'asd\abc'. basically so its not escaped.
Use:
(?<!\\)abc
This is a negative lookbehind. Basically this is saying: find me the string "abc" that is not preceded by a backslash.
The one problem with this is that if you want to allow escaping of backslashes. For example:
123\\abcdef
(ie the backslash is escaped) then it gets a little trickier.
$str = 'jfdg\abc';
var_dump(preg_match('#(?<!\\\)abc#', $str));
Try the regex:
(?<!\\)abc
It matches a abc
only if its not preceded by a \
精彩评论