All Projects → lmfresneda → mention-hashtag

lmfresneda / mention-hashtag

Licence: MIT License
Extract mentions (@mention) or hashtags (#hashtag) from any text

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mention-hashtag

is-regex
Is this value a JS regex?
Stars: ✭ 22 (+37.5%)
Mutual labels:  regex, regexp
js-diacritic-regex
Creates the inverse of transliterated string to a regex. What? Basically, diacritic insensitiveness
Stars: ✭ 20 (+25%)
Mutual labels:  regex, regexp
python-hyperscan
A CPython extension for the Hyperscan regular expression matching library.
Stars: ✭ 112 (+600%)
Mutual labels:  regex, regexp
IronRure
.NET Bindings to the Rust Regex Crate
Stars: ✭ 16 (+0%)
Mutual labels:  regex, regexp
RegExp-Learning
学习正则表达式
Stars: ✭ 30 (+87.5%)
Mutual labels:  regex, regexp
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+25%)
Mutual labels:  regex, regexp
Socially
Socially is a textView which is able to create separate clickable views according to your requirements.
Stars: ✭ 28 (+75%)
Mutual labels:  hashtag, regex
regexp-example
正则表达式实例搜集,通过实例来学习正则表达式。
Stars: ✭ 162 (+912.5%)
Mutual labels:  regex, regexp
RgxGen
Regex: generate matching and non matching strings based on regex pattern.
Stars: ✭ 45 (+181.25%)
Mutual labels:  regex, regexp
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+256.25%)
Mutual labels:  regex, regexp
regexp-expand
Show the ELisp regular expression at point in rx form.
Stars: ✭ 18 (+12.5%)
Mutual labels:  regex, regexp
retrie
Efficient Trie-based regex unions for blacklist/whitelist filtering and one-pass mapping-based string replacing
Stars: ✭ 35 (+118.75%)
Mutual labels:  regex, regexp
cregex
A small implementation of regular expression matching engine in C
Stars: ✭ 72 (+350%)
Mutual labels:  regex, regexp
Mentions
An easy way to add mentions and hashtags
Stars: ✭ 24 (+50%)
Mutual labels:  hashtag, mentions
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (+268.75%)
Mutual labels:  regex, regexp
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (+62.5%)
Mutual labels:  regex, regexp
moar
Deterministic Regular Expressions with Backreferences
Stars: ✭ 19 (+18.75%)
Mutual labels:  regex, regexp
Regaxor
A regular expression fuzzer.
Stars: ✭ 35 (+118.75%)
Mutual labels:  regex, regexp
globrex
Glob to regular expression with support for extended globs.
Stars: ✭ 52 (+225%)
Mutual labels:  regex, regexp
stringx
Drop-in replacements for base R string functions powered by stringi
Stars: ✭ 14 (-12.5%)
Mutual labels:  regex, regexp

mention-hashtag

npm npm Love Travis

Extract mentions (@mention) and/or hashtags (#hashtag) from any text

How to use

const extract = require('mention-hashtag')

const mentions = extract('Any text with @mention');
// mentions == ['@mention']

const hashtags = extract('Any text with #hashtag', '#');
// hashtags == ['#hashtag']

const all = extract('Any text with #hashtag and @mention and @othermention', 'all');
// all == { mentions: ['@mention', '@othermention'], hashtags: ['#hashtag'] }

NOTE: The extract of mentions is by default. For extract hashtags, the '#' symbol in second parameter is required.

Options

Exclude repeated tokens

const mentions = extract('Any text with @mention and @mention and @othermention', { unique: true });
// mentions == ['@mention', '@othermention']

const hashtags = extract('Any text with #hashtag and #hashtag and #otherhashtag', { unique: true, type: '#' });
// hashtags == ['#hashtag', '#otherhashtag']

const all = extract('Any text with #hashtag and #hashtag and @mention and @mention', { unique: true, type: 'all' });
// all == { mentions: ['@mention'], hashtags: ['#hashtag'] }

NOTE: The symbol '#' is communicated in 'type' property of second parameter

Remove '@' and '#' symbols

const mentions = extract('Any text with @mention and @othermention', { symbol: false });
// mentions == ['mention', 'othermention']

const hashtags = extract('Any text with #hashtag and #otherhashtag', { symbol: false, type: '#' });
// hashtags == ['hashtag', 'otherhashtag']

const all = extract('Any text with #hashtag and @mention', { symbol: false, type: 'all' });
// all == { mentions: ['mention'], hashtags: ['hashtag'] }

Mix

Unique, symbol and type properties are mixables

const mentions = extract('Any text with @mention and @mention and @othermention', { symbol: false, unique: true });
// mentions == ['mention', 'othermention']

const hashtags = extract('Any text with #hashtag and #hashtag and #otherhashtag', { symbol: false, unique: true, type: '#' });
// hashtags == ['hashtag', 'otherhashtag']

const all = extract('Any text with #hashtag and #hashtag and @mention and @mention', { symbol: false, unique: true, type: 'all' });
// all == { mentions: ['mention'], hashtags: ['hashtag'] }

Run test

$ npm install && npm test

License

MIT © lmfresneda

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].