Page 1 of 1

Regex on this string

Posted: Thu Dec 31, 2009 6:38 am
by klevis miho
What regex do I need on this string:

<span class="test">06:00</span> <span class="information"><a href="http://example.com/tesTing/0,123.html">Test</a>

to get this result:

06:00</span> <span class="information"><a>Test

The string's have have the same structure except for a variable url in the href.

I have this regex: #<span class="test">(.+?)</a>#s but it displays me the string with the actual href.

Re: Regex on this string

Posted: Thu Dec 31, 2009 3:09 pm
by tr0gd0rr
Kind of a strange text to search and find. I hope your reasoning is mostly academic.

Code: Select all

$test = '<span class="test">06:00</span> <span class="information"><a href="http://example.com/tesTing/0,123.html">Test</a>';
$regex = '#<span class="test">(.+?<a)[^>]+(>.+?)</a>#s';
$new = preg_replace($regex, $test, '$1$2'); // '06:00</span> <span class="information"><a>Test'