Package Exports
- mentions-regex
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mentions-regex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
The correct mention(s) regex. Regular expression for twitter, facebook, github, etc user mentions
Install
$ npm install mentions-regex
$ npm test
.metntionsRegex
Default regex is
\s+@(\w{1,30})\s+
[options]
{Object}startSpace
{Boolean} iffalse
, will remove starting\s+
from regexendSpace
{Boolean} iffalse
, will remove ending\s+
from regexlength
{Number} maximum length of mention, default30
match
{String} what to match, default is\w{1,30}
flags
{String} every valid RegExp flag, defaultundefined
dot
{Boolean} will use[A-Za-z0-9_.]
instead of\w
return
{RegExp}
Usage
For more use-cases see tests
var mentionsRegex = require('mentions-regex');
mentionsRegex().test('github @tunnckoCore')
//=> false
mentionsRegex({flags: 'g'}).test('github @tunnckoCore')
//=> false
mentionsRegex({endSpace: false}).test('github @tunnckoCore')
//=> true
var str = '@first git @tunnckoCore and @face some @al.so email@here.com glob @last'
str.match(mentionsRegex())
//=> [' @tunnckoCore ']
str.match(mentionsRegex({flags: 'g'}))
//=> [' @tunnckoCore ', ' @face ']
str.match(mentionsRegex({flags: 'g', startSpace: false}))
//=> ['@first ', '@tunnckoCore ', '@face ']
str.match(mentionsRegex({flags: 'g', endSpace: false}))
//=> [' @tunnckoCore ', ' @face ', ' @al', ' @last']
str.match(mentionsRegex({flags: 'g', startSpace: false, endSpace: false}))
//=> ['@first', '@tunnckoCore', '@face', '@al', '@here', '@last']
str.match(mentionsRegex({length: 5}))
//=> [' @face ']
str.match(mentionsRegex({flags: 'g', dot: true}))
//=> [' @tunnckoCore ', ' @face ', ' @al.so ']
str.match(mentionsRegex({flags: 'g', dot: true, length: 5}))
//=> [' @face ', ' @al.so ']
str.match(mentionsRegex({flags: 'g', dot: true, startSpace: false}))
//=> ['@first ', '@tunnckoCore ', '@face ', '@al.so ', '@here.com ']
str.match(mentionsRegex({flags: 'g', dot: true, startSpace: false, endSpace: false}))
//=> ['@first', '@tunnckoCore', '@face', '@al.so', '@here.com ', '@last']
Author
Charlike Mike Reagent
License 
Copyright (c) 2014 Charlike Mike Reagent, contributors.
Released under the MIT
license.
Powered and automated by readdirp + hogan.js, December 21, 2014