Using REGEX To Replacing Parameters Within A Tag

I am working on a tag to automatically set the width and height of embedded videos within an article to 480x300. I used the ColdFusion code attached, however that also changes the width and height of any embedded images. How can I change the code to have a regex expression to only alter the width and height within an EMBED OR OBJECT tag?
thisArticle = REReplaceNoCase(thisArticle, 'width="([0-9]+)" height="([0-9]+)"','width="480" height="300"',"all");

Open in new window

maniadiggityAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
try:
thisArticle = REReplaceNoCase(thisArticle, '(embed|object).*?width="([0-9]+)" height="([0-9]+)"','width="480" height="300"',"all");
0
maniadiggityAuthor Commented:
That didn't work, when using that code I had the following HTML code:

<cfset thisArticle = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

<br><br>
<p align="center"><a href="http://www.google.com/"><img src="http://t2.gstatic.com/images?q=tbn:Km46QiDGe3ZKnM:http://www.dallasvoice.com/instant-tea/wp-content/uploads/obama3.jpg" width="98" height="122" border="1" /></a></p>'>

It resulted in the following code after using that regex:

<width="480" height="300"><param name="movie" value="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><width="480" height="300"></width="480" height="300" border="1" /></a></p>
0
Pui_YunCommented:
try:
thisArticle = REReplaceNoCase(thisArticle, '((embed|object).*?)width="([0-9]+)" height="([0-9]+)"','\1width="480" height="300"',"all");

Hope this helps!
P.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Pui_YunCommented:
actually try this:
thisArticle = REReplaceNoCase(thisArticle, '(<(embed|object).*?)width="([0-9]+)" height="([0-9]+)"','\1width="480" height="300"',"all");

P.
0
maniadiggityAuthor Commented:
Very close, except that it's not changing the width and height to 480x300, here was the resulting HTML code after running the regex:

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

<br><br>
<p align="center"><a href="http://www.google.com/"><img src="http://t2.gstatic.com/images?q=tbn:Km46QiDGe3ZKnM:http://www.dallasvoice.com/instant-tea/wp-content/uploads/obama3.jpg" width="98" height="122" border="1" /></a></p>
0
Pui_YunCommented:
This worked for me.  See attached.

P.
<cfset thisArticle = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PmoZLMpozYM&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

<br><br>
<p align="center"><a href="http://www.google.com/"><img src="http://t2.gstatic.com/images?q=tbn:Km46QiDGe3ZKnM:http://www.dallasvoice.com/instant-tea/wp-content/uploads/obama3.jpg" width="98" height="122" border="1" /></a></p>'>

<cfset thisArticle = REReplaceNoCase(thisArticle, '(<(object|embed)[^>]*)width="([0-9]+)" height="([0-9]+)"','\1width="480" height="300"',"all")>
<cfoutput>#thisArticle#</cfoutput>

Open in new window

0
Pui_YunCommented:
Hi maniadiggity,
I wasn't very clear in my last post, I change the regex to:
thisArticle = REReplaceNoCase(thisArticle, '(<(object|embed)[^>]*)width="([0-9]+)" height="([0-9]+)"','\1width="480" height="300"',"all")

Hope this helps.
P.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maniadiggityAuthor Commented:
That worked, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.