SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Simple replace.

  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple replace.

    Hi.
    I'm not very good at regex therefore
    I'd like to know if this is the right way:

    var oldUrl= 'http://www.youtube.com/watch?v=I0LuhwMvdig';
    var re = /watch\?v=/;
    var newUrl = oldUrl.replace(re, "v/");
    alert(newUrl);
    // 'http://www.youtube.com/v/I0LuhwMvdig';

    Bye.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Yes, that appears to have no major issues.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •