Hi,

I am hoping someone can help me with a regex.

I think it is pretty simple. I could probably cobble something together
using string manipulations, but I thought regex might be a more elegant
solution, but I dont have much experience with reg ex and I need to do this
ASAP.

Any help would be much appreciated.

I need to replace any instances of height="x" & width="x", with height="100"
& width="100", from a string.

Basically, I need to dynamically change the height and width that a youtube
video renders at within a browser.eg.

<object width="425" height="355"><param name="movie"
value="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"></param><param
name="wmode" value="transparent"></param><embed
src="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

regex, to replace the height and width within this string to force a 100px
square. I will never know the size of the video a user wants to display, so
I can't use a standard replace.

I am using ASP & vbscript.

Any help would be much appreciated.

--
Regards

Chris

Re: regex by James

James
Tue Apr 22 12:41:54 CDT 2008

"Chris Dangerfield" <csdangerfield@yahoo.co.uk> wrote in message
news:_JOdnfKoYJYsnpPVnZ2dnUVZ8t6inZ2d@plusnet...
> Hi,
>
> I am hoping someone can help me with a regex.
>
> I think it is pretty simple. I could probably cobble something together
> using string manipulations, but I thought regex might be a more elegant
> solution, but I dont have much experience with reg ex and I need to do
> this ASAP.
>
> Any help would be much appreciated.
>
> I need to replace any instances of height="x" & width="x", with
> height="100" & width="100", from a string.
>
> Basically, I need to dynamically change the height and width that a
> youtube video renders at within a browser.eg.
>
> <object width="425" height="355"><param name="movie"
> value="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"></param><param
> name="wmode" value="transparent"></param><embed
> src="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"
> type="application/x-shockwave-flash" wmode="transparent" width="425"
> height="355"></embed></object>
>
> regex, to replace the height and width within this string to force a 100px
> square. I will never know the size of the video a user wants to display,
> so I can't use a standard replace.
>
> I am using ASP & vbscript.
>
> Any help would be much appreciated.

You could use a pattern like the one below (assume your HTML code is in
'sCode' variable):

Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.IgnoreCase = True
oRegEx.Global = True
oRegEx.Pattern = "(width|height)(.?=.?"")(\d*?)("")"
sCode = oRegEx.Replace(sCode, "$1$2100$4")



Re: regex by Alexander

Alexander
Sat Apr 26 10:18:18 CDT 2008

Chris Dangerfield schrieb:

> I am hoping someone can help me with a regex.
>
> I need to replace any instances of height="x" & width="x", with height="100"
> & width="100", from a string.
>
>
> <object width="425" height="355"><param name="movie"
> value="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"></param><param
> name="wmode" value="transparent"></param><embed
> src="http://www.youtube.com/v/t9_TPM1lKV8&hl=en"
> type="application/x-shockwave-flash" wmode="transparent" width="425"
> height="355"></embed></object>

Dim rx
Dim html
Const SIZE_VH = "100"

Set rx = New RegExp
rx.Pattern = "(\b(width|height)="")([\d\.]+)("")"
rx.Global = true
rx.Ignorecase = true


html = "<object width=""425"" height=""355""><param name=""movie""" _
& "value=""http://www.youtube.com/v/t9_TPM1lKV8&hl=en"">" _
& "</param><param name=""wmode"" value=""transparent""></param>" _
& "<embed src=""http://www.youtube.com/v/t9_TPM1lKV8&hl=en""" _
& " type=""application/x-shockwave-flash"" wmode=""transparent""" _
& " width=""425"" height=""355""></embed></object>"

MsgBox rx.Replace (html, "$1" & SIZE_VH & "$4")





MfG,
Alex