mentions-hashtags

Crates.iomentions-hashtags
lib.rsmentions-hashtags
version0.1.0
created_at2025-07-20 15:36:55.792238+00
updated_at2025-07-20 15:36:55.792238+00
descriptionExtracts @mentions and #hashtags from text (like social media descriptions). Built in safe, fast, idiomatic Rust using regex.
homepagehttps://github.com/rocketnozzle/mentions-hashtags-rs
repositoryhttps://github.com/rocketnozzle/mentions-hashtags-rs
max_upload_size
id1761196
size15,901
Rocket Nozzle (rocketnozzle)

documentation

README

๐Ÿ“ฃ 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 mentions_hashtags::mentions_hashtags::*;

let input = "@charlidamelio @GucciOfficial just posted! #fyp #CapCut #Chanel";
let result = parse_mentions_hashtags(input, true, true).unwrap();

assert_eq!(result.mentions, vec!["@charlidamelio", "@GucciOfficial"]);
assert!(result.hashtags.contains(&"#fyp".to_string()));
assert!(result.hashtags.contains(&"#Chanel".to_string()));

๐Ÿ› ๏ธ Functions

parse_mentions_hashtags(description, mentions, hashtags) -> Result<MentionsHashtags, Box<dyn Error>>

Parse both or either.

  • โœ… Set mentions = true to extract @users
  • โœ… Set hashtags = true to 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 Vec if nothing found
  • ๐Ÿ›ก๏ธ No panics
  • ๐Ÿ” Uses regex and HashSet only

๐Ÿงช Testing

Run tests:

cargo test

Covers:

  • ๐ŸŽฅ Instagram, TikTok and YouTube examples
  • โ™ป๏ธ Duplicates
  • โœ๏ธ Hashtags with punctuation
  • ๐Ÿˆณ Empty input

๐Ÿ“„ License

MIT

Commit count: 0

cargo fmt