Link to home
Start Free TrialLog in
Avatar of ray-solomon
ray-solomonFlag for United States of America

asked on

Regex to remove extra attributes

I need a regex that can strip out the extra mce_src or mce_href attributes from a string.
FYI: The location of the "mce_*" attributes could be on either side of the src or href attributes.


If this helps, I think this is how Wordpress does it in javascript:
I could be mistaken though.
s= s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s= s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s= s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s= s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');


Below is what it looks like.

This "img" tag:

<img mce_src="http://www.google.com/intl/en_ALL/images/logo.gif" src="http://www.google.com/intl/en_ALL/images/logo.gif" height="110" width="276">

should look like this:

<img src="http://www.google.com/intl/en_ALL/images/logo.gif" height="110" width="276">




This "a" tag:

<a href="http://www.domain.com/mypage.php" mce_href="http://www.domain.com/mypage.php">My link</a>

should look like this:

<a href="http://www.domain.com/mypage.php">My link</a>
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ray-solomon

ASKER

Nice. Thank you bol.
Your welcome!  I'm glad I could help.  Thank you for the grade, the points and the fun question.

bol
Avatar of bjh497
bjh497

I have a similar question here if you can help,

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27577833.html

same problem but the expression here removes closing tags from image