mentions-hashtags 0.1.0

Extracts @mentions and #hashtags from text (like social media descriptions). Built in safe, fast, idiomatic Rust using regex.
Documentation
  • Coverage
  • 62.5%
    5 out of 8 items documented3 out of 4 items with examples
  • Size
  • Source code size: 15.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 386.63 kB This is the summed size of all files generated by rustdoc for all configured targets
  • ร˜ build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rocketnozzle/mentions-hashtags-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rocketnozzle

๐Ÿ“ฃ 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