My string is like .html?request=516359075128086&to%5B0%5D=100004408050639&to%5B1%5D=1516147434&_=_
This string is result of a app invitation url redirect request sent to fb.
And what i want to do is, to extract user ids 100004408050639 and 1516147434 to an array.
I tried var fbCode = testString.match(/to%5B0%5D=(.*)&/);
but this returns only one of these numbers, ie first occurrence.
My string is like https://www.facebook./connect/login_success.html?request=516359075128086&to%5B0%5D=100004408050639&to%5B1%5D=1516147434&_=_
This string is result of a app invitation url redirect request sent to fb.
And what i want to do is, to extract user ids 100004408050639 and 1516147434 to an array.
I tried var fbCode = testString.match(/to%5B0%5D=(.*)&/);
but this returns only one of these numbers, ie first occurrence.
2 Answers
Reset to default 5var str = "https://www.facebook./connect/login_success.html?request=516359075128086&to%5B0%5D=100004408050639&to%5B1%5D=1516147434&_=_";
var re = new RegExp("to%5B[01]%5D=(\\d+)", "g");
When using the g
modifier for global search and want to get matches for a (
group )
, could loop through the matches. Those for the first parenthesized group will be in [1]
var matches = [];
while(matches = re.exec(str)) {
console.log(matches[1]);
}
Your regex specifies %5B0%5D
which translate to [0]
. The second user ID es with index 1 ([1]
) which is encoded as %5B1%5D
. If you want to accept any (numeric) user-Id-index, use '/to%5B\d+%5D=(.*?)&/g
' as your regex which allows any number (\d+
) as well as being global.
Regards.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745046345a4608120.html
评论列表(0条)