JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1120
  • Score
    100M100P100Q129651F
  • License

The correct mention(s) regex. Regular expression for twitter, facebook, github, etc user mentions

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

npm versi mit license build status deps status regexps org

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} if false, will remove starting \s+ from regex
    • endSpace {Boolean} if false, will remove ending \s+ from regex
    • length {Number} maximum length of mention, default 30
    • match {String} what to match, default is \w{1,30}
    • flags {String} every valid RegExp flag, default undefined
    • 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 MIT license

Copyright (c) 2014 Charlike Mike Reagent, contributors.
Released under the MIT license.


Powered and automated by readdirp + hogan.js, December 21, 2014