giuseppe giuseppe - 1 year ago 86
PHP Question

Trouble With Regexp

I have to replace matches of patterns like

within a
For example, a
like this: .....

should become: .....

In other words, I have to filter out any occurrence of
from the URL.
I will use php for that.
I tried with RegExp:


But it matches only strings like
. Strings like
are not matched.
Any hint appreciated.

Answer Source

You could do this:

$url = "/pippo:2/mypar:asa/7pippo:1/";
$stripped = preg_replace("/\/mypar:.*?(\/|$)/", "$1", $url);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download