Replace src attribute in a string.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Replace src attribute in a string.

Post by JellyFish »

Hey guys. This one's a bit tricky.

I have this big string of html. And I need a way to replace the first occurrence of anything in between [src="] and ["] or [src='] and ['] in javascript.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That would probably be regex if it's not DOM elements.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

feyd wrote:That would probably be regex if it's not DOM elements.
It's not DOM elements. Like I said it's a string, stored in an attribute to an element.

I would think it would be regex. But how would I accomplish this? I could use the .replace() method. But I don't know how I could select anything and everything that's wrapped around qoutes and "src=". Could someone give me a hint on this one. I'm not that great at regex. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Start trying something. There are plenty of examples in the Regex forum.
Post Reply