user1091856
user1091856

Reputation: 3158

Javascript/Regexp: Getting facebook album's id from url?

function sa_get_facebook_album_id(url){
    var m = url.match(/\?set=a\.[0-9]*\./);

    return m;
}

This function is supposed to return an album's ID after its URL is passed.

But I want to get ONLY the numbers ([0-9]) and nothing else.

How can this be done?

Upvotes: 0

Views: 348

Answers (1)

João Silva
João Silva

Reputation: 91349

Use a capturing group to store the id:

function sa_get_facebook_album_id(url){
    var m = url.match(/\?set=a\.([0-9]*)\./);
    return m[1];
}

The capturing group is in parenthesis, i.e., ([0-9]*), and you can refer to it later, using m[1]. Note that m[0] contains the entire matched string, m[1] the first captured group, and so on.

DEMO.

Upvotes: 1

Related Questions