[Javascript] Selecting certain areas of text in a string

Rees, Mark Mark.Rees at astrazeneca.com
Wed Mar 11 05:20:30 CDT 2009


If you need to match anything more complex than a single movie name e.g. if you need to match somemovie1.flv, somemovie2.flv and so on, you could consider a regular expression. 

Here's a few links to get started

A general introduction
http://www.regular-expressions.info/tutorial.html

JavaScript's implementation
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp

Firefox has a good add-on called "regular expressions tester" which you can use to fine tune your expression. 

You can use it as the first parameter in the string.replace command. You will find an explanation and some examples here
https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/String/Replace


--------------------------------------------------------------------------
AstraZeneca UK Limited is a company incorporated in England and Wales with registered number: 03674842 and a registered office at 15 Stanhope Gate, London W1K 1LN.
Confidentiality Notice: This message is private and may contain confidential, proprietary and legally privileged information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorised use or disclosure of the contents of this message is not permitted and may be unlawful.
Disclaimer: Email messages may be subject to delays, interception, non-delivery and unauthorised alterations. Therefore, information expressed in this message is not given or endorsed by AstraZeneca UK Limited unless otherwise notified by an authorised representative independent of this message. No contractual relationship is created by this message by any person unless specifically indicated by agreement in writing other than email.
Monitoring: AstraZeneca UK Limited may monitor email traffic data and content for the purposes of the prevention and detection of crime, ensuring the security of our computer systems and checking Compliance with our Code of Conduct and Policies.
-----Original Message-----
From: javascript-bounces at lists.evolt.org
[mailto:javascript-bounces at lists.evolt.org]On Behalf Of Nick Fitzsimons
Sent: 10 March 2009 17:30
To: JavaScript List
Subject: Re: [Javascript] Selecting certain areas of text in a string


Apologies if this gets posted twice - my webmail is playing up :-(

Assuming your <object> element has the ID "movie" then

var movie = document.getElementById("movie");
movie.src = movie.src.replace(/somevideo.flv/, "othervideo.flv");

should do the trick.

Regards,

Nick.

On Tue, March 10, 2009 3:35 pm, javascript at webdesignofficina.com wrote:
>
> Hi there,
>
> Currently trying to change the url of an embedded element in a page...
> My problem is that many other parameters are passed along the url of
> the object, in the src property:
>
> src="../pluginsv/mediaplayer.swf?file=http://www.somesite.com/video/
> somevideo.flv&autostart=true&displayheight=202&allowfullscreen=over&controlbar=over&usefullscreen=true&backcolor=0x121212&frontcolor=0xffffff&lightcolor=0x000000&bufferlength=10"
>
> I'd like to only rewrite this part: file=http://www.somesite.com/
> video/somevideo.flv
> Rest of the parameters should remain untouched...
>
> I know I should use String.replace, something like:
>
> var str="somevideo.flv!";
> document.write(str.replace(/somevideo.flv/,"othervideo.flv"));
>
> But I have absolutely no idea on how target this piece of text only in the
> whole src="...", starting from ending file path, from / to .flv
>
> Any help would be greatly appreciated.
>
> Thank you.
>
> Best regards,
>
> Guillaume Stricher




More information about the Javascript mailing list