i have below string from which I have to extract username and ID.
This is a string which has a @[User Full Name](contact:1) data inside.
To get username and contact id from above string I am using this regex pattern.
var re = /\@\[(.*)\]\(contact\:(\d+)\)/;
text = text.replace(re,"username:$1 with ID: $2");
// result == username: User Full Name with ID: 1
It works perfectly now issue is I have multiple usernames in string, I tried using /g (global) but its not replacing properly: Example string:
This is a string which has a @[User Full Name](contact:1) data inside. and it can also contain many other users data like @[Second Username](contact:2) and @[Third username](contact:3) and so many others....
when used global I get this result:
var re = /\@\[(.*)\]\(contact\:(\d+)\)/g;
text = text.replace(re,"username:$1 with ID: $2");
//RESULT from above
This is a string which has a user username; User Full Name](contact:1) data inside. and it can also contain many other users data like @[[Second Username](contact:2) and @[Third username and ID: 52 and so many others....