1

I want to remove every class="imgbrd lazy" and after that delete any scr="" and after that change data-original to scr

Individually it looks like this

$input = preg_replace('#class="imgbrd lazy"#s', '' ,$input);
$input = preg_replace('#src=".*?"#s', '' ,$input); 
$input = preg_replace('#data-original=#s', 'src=' ,$input); 

Suppose the $input is this

<img class="imgbrd lazy" src="/something/iage.png" data-original="/albums/uploadedpics/small1/017246.jpg" border="0">

The issue is that scr get deleted even if "imgbrd lazy" isn't found

user2650277
  • 6,289
  • 17
  • 63
  • 132

2 Answers2

2
class="imgbrd lazy"([\s\S]*?)src=".*?"

Use this.Replace by $1.See demo.

https://regex101.com/r/tX2bH4/40

vks
  • 67,027
  • 10
  • 91
  • 124
  • it works but if there are any attribute between the `class="imgbrd lazy"` and `scr` , it delete that as well – user2650277 Jan 19 '15 at 15:26
  • @user2650277 no it will not be deleted.See demo.https://regex101.com/r/tX2bH4/51 Replace by `$1`. – vks Jan 19 '15 at 15:29
1

Seems like you want something like this,

class="imgbrd lazy"\s+src=".*?"\s+data-original=

Use the baove regex and then replace the matched charcaters with src=

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274