ray-solomon
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>
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*\"
s= s.replace(new RegExp('mce_href\\s*=\\s*\
s= s.replace(new RegExp('mce_src\\s*=\\s*\"
s= s.replace(new RegExp('mce_href\\s*=\\s*\
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your welcome! I'm glad I could help. Thank you for the grade, the points and the fun question.
bol
bol
I have a similar question here if you can help,
http://www.experts-exchang e.com/Web_ Developmen t/Web_Lang uages-Stan dards/PHP/ Q_27577833 .html
same problem but the expression here removes closing tags from image
http://www.experts-exchang
same problem but the expression here removes closing tags from image
ASKER