php - Regular Expression working in online test tool, but not in my app
Get the solution ↓↓↓Solution:
Just add an escape:
preg_match('/[\/\\\](\d+_\d+_\d+_\d+)[\/\\\]/', $file, $matches);
// here __^ and __^
Answer
Solution:
You need to add one more backslash in your pattern.
preg_match('/[\/\\\](\d+_\d+_\d+_\d+)[\/\\\]/', $file, $matches);
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:
preg_match('/^\/.*(\d+_\d+_\d+_\d+)\/.*$/', $file, $matches);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.