UNPKG

mentions-regex

Version:

100% twitter compatible `@mentions` regex! Regular expression for matching `@username` mentions, as used on twitter, facebook, github, etc.

100 lines (64 loc) 3.46 kB
## [![npm version][npmjs-img]][npmjs-url] [![standard style][standard-img]][standard-url] [![build status][travis-img]][travis-url] [![coveralls img][coveralls-img]][coveralls-url] [![deps status][daviddm-img]][daviddm-url] > 100% twitter compatible `@mentions` regex! Regular expression for matching `@username` mentions, as used on twitter, facebook, github, etc. ## Install ``` npm i --save mentions-regex npm test ``` ## [mentionsRegex](index.js#L18) > Compatible twitter mentions regex, not only of course! * `[dot]` **{Boolean}** if `true` it will allow to match dots * `return` **{RegExp}** ## Usage > For more use-cases see [tests](./test.js) ```js var mentionsRegex = require('mentions-regex'); mentionsRegex().test('foo @bar baz'); //=> true mentionsRegex().exec('foo @bar baz')[1]; //=> 'bar' mentionsRegex().test('foo email@bar.com baz'); //=> false mentionsRegex(true).test('foo email@bar.com baz'); //=> false mentionsRegex(true).test('foo @bar.com baz'); //=> true mentionsRegex(true).exec('foo @bar.com baz')[1]; //=> 'bar.com' ``` ## Related - [abbrev-kindof](https://github.com/tunnckoCore/abbrev-kindof#readme): `kind-of` with single letter abbreviations to javascript native types, like `kindof(val, 'soa')` will return true if `val` is string, object or array. - [copyright-regex](https://github.com/regexps/copyright-regex): Regex for matching and parsing copyright statements. - [dirname-regex](https://github.com/regexps/dirname-regex): Regular expression for matching the directory part of a file path. - [glob-path-regex](https://github.com/regexps/glob-path-regex): Regular expression for matching the parts of glob pattern. - [regexify](https://github.com/hemanth/regexify): Regex everything! ## Author **Charlike Mike Reagent** + [gratipay/tunnckoCore][author-gratipay] + [twitter/tunnckoCore][author-twitter] + [github/tunnckoCore][author-github] + [npmjs/tunnckoCore][author-npmjs] + [more ...][contrib-more] ## License [![MIT license][license-img]][license-url] Copyright (c) 2014-2015 [Charlike Mike Reagent][contrib-more], [contributors][contrib-graf]. Released under the [`MIT`][license-url] license. [npmjs-url]: http://npm.im/mentions-regex [npmjs-img]: https://img.shields.io/npm/v/mentions-regex.svg?style=flat&label=mentions-regex [coveralls-url]: https://coveralls.io/r/regexps/mentions-regex?branch=master [coveralls-img]: https://img.shields.io/coveralls/regexps/mentions-regex.svg?style=flat [license-url]: https://github.com/regexps/mentions-regex/blob/master/LICENSE.md [license-img]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat [travis-url]: https://travis-ci.org/regexps/mentions-regex [travis-img]: https://img.shields.io/travis/regexps/mentions-regex.svg?style=flat [daviddm-url]: https://david-dm.org/regexps/mentions-regex [daviddm-img]: https://img.shields.io/david/dev/regexps/mentions-regex.svg?style=flat [author-gratipay]: https://gratipay.com/tunnckoCore [author-twitter]: https://twitter.com/tunnckoCore [author-github]: https://github.com/tunnckoCore [author-npmjs]: https://npmjs.org/~tunnckocore [contrib-more]: http://j.mp/1stW47C [contrib-graf]: https://github.com/regexps/mentions-regex/graphs/contributors [standard-url]: https://github.com/feross/standard [standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat *** _Proudly generated by [docks(1)](https://github.com/tunnckoCore) on May 4, 2015_