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.
Regex on this string
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Regex on this string
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'