1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regex for Megavideo URL

Discussion in 'General Scripting Chat' started by neoakenz, Sep 9, 2011.

  1. neoakenz

    neoakenz Newbie

    Joined:
    Nov 26, 2008
    Messages:
    45
    Likes Received:
    1
    How do I write the Regex for this: http://www.megavideo.com/v/B4PZHP0Nb2e8a877f8378e778446318596415780

    to pull out B4PZHP0N?
     
  2. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    Code:
    \w{8,12}$
    The above works by matching any alpha-numeric matches between 8 and 12 characters from the end of the string.
    So for it to work, you will need that "B4PZHP0N" part to ALWAYS be at the end of the string.

    (I added 8-12 as I'm not sure what's the max length that MU uses for that identifier).


    Another way to do it though, would be:

    Code:
    &v=\w{8,12}
    The above works by matching any alpha-numeric matches after "&v=" which might be better for you. (Between 8 and 12 characters long)
     
    Last edited: Sep 9, 2011
  3. xenon2010

    xenon2010 Regular Member

    Joined:
    Apr 27, 2010
    Messages:
    231
    Likes Received:
    48
    Occupation:
    web and desktop apps programmer
    Location:
    prison
    Home Page:
    Code:
    &v=(.*?) or &v=(.+?)