ASP, vbscript - regex replace

I want to replace some text in the following code that users can insert in a CMS system:

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/W8_Kfjo3VjU&hl=nl_NL&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/W8_Kfjo3VjU&hl=nl_NL&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

As you can see this is from Youtube to embed a video.

I want to replace these strings in the code:

width="480"
height="385"

These strings can be variable. For instance someone can just insert: width="2480"

I want to avoid people from doing that.

Those 2 stings need to be replaced by:

width="320"
height="200"

Can anyone give some code to do that ?

Also any idea's how to do a basic validation that the code people insert is indeed to embed a Youtube video ?
Dutch_guyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

jostranderCommented:
Maybe something like this:
oldText="<object width=""480"" height=""385""><param name=""movie"" value=""http://www.youtube.com/v/W8_Kfjo3VjU&hl=nl_NL&fs=1&""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowscriptaccess"" value=""always""></param><embed src=""http://www.youtube.com/v/W8_Kfjo3VjU&hl=nl_NL&fs=1&"" type=""application/x-shockwave-flash"" allowscriptaccess=""always"" allowfullscreen=""true"" width=""480"" height=""385""></embed></object>"

msgbox oldText

newText=FixDimensions(oldText)

msgbox newText




Function FixDimensions(myText)
	
	'Set objRegEx = CreateObject("VBScript.RegExp")
	Set objRegEx = New RegExp

	objRegEx.Global=True
	'objRegEx.MultiLine = True 
	objRegEx.IgnoreCase=True
	
	
	objRegEx.Pattern = "width=""+[0-9]+"""
	Set colMatches_w = objRegEx.Execute(myText)  
	If colMatches_w.count > 0 then myText=objRegEx.Replace(myText,"width=""320""")
	
	objRegEx.Pattern = "height=""+[0-9]+"""
	Set colMatches_h = objRegEx.Execute(myText)  
	If colMatches_h.count > 0 then myText=objRegEx.Replace(myText,"height=""200""")

	FixDimensions=myText

End Function

Open in new window

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
Dutch_guyAuthor Commented:
Works great! Thanks alot !
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
ASP

From novice to tech pro — start learning today.