I have an assignment where I need to retrieve data from some twitter posts using MongoDB, and have been sitting with a problem for a few hours now. I need to extract the mentioned user (In Twitter you @TheirUsername to mention them), and have a hard time doing so, I've tried using substrCP, and finding indexes for where the "@" begins, but can't figure out how to find where the "@" stops, as names have a different length, and there can be any character after the name ends, such as "?", "." etc.
Therefore I was using the regex pattern: /@\w+/ to find out if the tweet has a string of characters that includes an @ symbol, followed by some word. This works really well in finding out if the tweet has an @Someone in it, but I still cannot figure out how to "extract" it.
(Btw. I've been using aggregate to do this, so I could pipe it through $match, then $project, and finally $sort)
Looks something like this:
https://hastebin.com/adohogedil.bash
An example of a string that needs to extract the username is:
"damnnn! @white_cat22 i missed 11:11"
Where I only want the "@white_cat22" part.
EDIT: After googling a bit, I think a better way to describe it is as follows, I need to retrieve the matched regex pattern on the string that is being tested on.
What can I do to extract the mentioned username? Any help would be greatly appreciated! (edited)