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           __^
131

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!

478

Answer

Solution:

I would try this:

preg_match('/^\/.*(\d+_\d+_\d+_\d+)\/.*$/', $file, $matches);

People are also looking for solutions to the problem: php - Regarding unique username

Source

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.

Ask a Question

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.

Similar questions

Find the answer in similar questions on our website.