需要匹配PHP正则表达式中的多个反斜杠

I'm trying to match 4 backslahes using preg_match.

preg_match('/\\\\\\\\/',$subject) works fine, but preg_match('/\\{4}/',$subject) doesn't.

Perhaps I'm using {} incorrectly. Could anyone advise?

Ok I got it: Two backslashes mean you want one backslash in your string: So for the regex it looks like this: /\{4}/ Which means you want to escape the {

What you need here is:

preg_match('/\\\\{4}/', $subject);

That looks for the regex like this: /\\{4}/ and works properly.

Use this:

preg_match('/(?:\\\\){2}/',$subject, $m);

It matches 4 backslashes.

Regex is the wrong tool when you're looking for a literal string.

strpos($subject, str_repeat("\\",4)) !== false