Reputation: 531
I have a string and I wrote following code to extract "NewUsers19" from that.
function getNoOfUsers() {
var noSpace = "UserRejectedOrderCount25NewUsers19FundedNewUsers14DepositAmount($)43165.23DepositCount75WithdrawAmount($)53510";
var regex = /(?:NewUsers)([0-9]+)/;
var value = regex.exec(noSpace);
return value;
}
The regex worked fine in online editors but I don't know why it does not work in Google App Script. Any help will be appreciated.
Upvotes: 2
Views: 1195
Reputation: 626738
You should remove the non-capturing group and then return value[1]
:
function getNoOfUsers() {
var noSpace = "UserRejectedOrderCount25NewUsers19FundedNewUsers14DepositAmount($)43165.23DepositCount75WithdrawAmount($)53510";
var regex = /NewUsers([0-9]+)/;
var value = regex.exec(noSpace);
return value ? value[1] : "";
}
Tested in Google Docs:
Upvotes: 1