Pamela Sillah Pamela Sillah - 1 year ago 105
PHP Question

WordPress regex not working as expected

I need to put a string like

into regex form. I tried
and also
, but none of them are working. What is the correct way?

Answer Source

Your problem is that you aren't escaping the / character with a backslash.

Another problem you could face immediately after solving that one, is that you are using the $ character, which means end of line. If there are more characters afterwards, even just a single space, then it won't match.

If you try:


You'll probably find that it matches just fine. The brackets I added in will capture id=3 in capture group #1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download