php - Regular Expression working in online test tool, but not in my app
928
Solution:
Just add an escape:
preg_match('/[\/\\\](\d+_\d+_\d+_\d+)[\/\\\]/', $file, $matches);
// here __^ and __^
Just add an escape:
preg_match('/[\/\\\](\d+_\d+_\d+_\d+)[\/\\\]/', $file, $matches);
// here __^ and __^
People are also looking for solutions to the problem: php - Regarding unique username
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
Find the answer in similar questions on our website.
Answer
Solution:
You need to add one more backslash in your pattern.
Because the backslash is itself a special character, you need to escape it with another backslash ( \ ) if you want to include it literally in an expression. What ’ s more, because a backslash followed by another character within a string is itself seen as an escaped character in PHP, you usually need to add a third backslash ( \\ ). Phew!
Answer
Solution:
I would try this: