Search code examples
actionscript-3apache-flexflickr

Flickr Photo ID Regex - Actionscript


Trying to create a regex for flex that accepts a url in the form of:

http://www.flickr.com/photos/anguslturner/<photoid>/

and extract the following part (the id)

http://www.flickr.com/photos/anguslturner/[0]/

Searched through Google and can't find anything that works successfully...


Solution

  • Not pure RegExp but:

    var s:String = "http://www.flickr.com/photos/anguslturner";
    var username:String = s.split("/photos/")[1];
    trace(username);  // returns anguslturner
    

    if you want to allow anything after the username:

    var s:String = "http://www.flickr.com/photos/anguslturner/somethinganythinghere";
    var username:String = s.split("/photos/")[1];
    trace(username.split("/")[0]); // returns anguslturner