๐ฃ mentions_hashtags
Extracts @mentions and #hashtags from text (like social media descriptions). Built in safe, fast, idiomatic Rust using regex.
โจ What it does
- ๐งโ๐ผ Pulls out all mentions (e.g.
@MrBeast,@DiorOfficial) - ๐ Pulls out all hashtags (e.g.
#fyp,#LouisVuitton) - โป๏ธ Removes duplicates
- ๐ก Keeps original casing
- โ๏ธ Works with common username formats (letters, numbers,
_,-,.)
๐ Example
use *;
let input = "@charlidamelio @GucciOfficial just posted! #fyp #CapCut #Chanel";
let result = parse_mentions_hashtags.unwrap;
assert_eq!;
assert!;
assert!;
๐ ๏ธ Functions
parse_mentions_hashtags(description, mentions, hashtags) -> Result<MentionsHashtags, Box<dyn Error>>
Parse both or either.
- โ
Set
mentions = trueto extract@users - โ
Set
hashtags = trueto extract#tags
parse_mentions(description) -> Result<Vec<String>>
Extract all @user names (no duplicates).
parse_hashtags(description) -> Result<Vec<String>>
Extract all #tags (no duplicates).
๐ Notes
- โ ๏ธ Case-sensitive matching (but still deduplicated)
- ๐ณ๏ธ Returns empty
Vecif nothing found - ๐ก๏ธ No panics
- ๐ Uses
regexandHashSetonly
๐งช Testing
Run tests:
Covers:
- ๐ฅ Instagram, TikTok and YouTube examples
- โป๏ธ Duplicates
- โ๏ธ Hashtags with punctuation
- ๐ณ Empty input
๐ License
MIT