Skip to content

Commit 9f9c37d

Browse files
author
tunnckoCore
committed
update regex
1 parent 24e51d0 commit 9f9c37d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

index.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
'use strict';
99

1010
/**
11-
* The correct mention(s) regex. Regex done right!
11+
* Compatible twitter mentions regex
1212
*
13-
* @param {Object} `options`
13+
* @param {Boolean} `dot` if `true` it will allow to match dots
1414
* @return {RegExp}
15+
* @api public
1516
*/
16-
module.exports = function metntionsRegex(options) {
17-
options = options || {};
18-
19-
var startSpace = options.startSpace === false ? '' : '\\s+';
20-
var endSpace = options.endSpace === false ? '' : '\\s+';
21-
var length = '{1,' + (options.length || 30) + '}';
22-
var match = options.match || '\\w' + length;
23-
24-
match = options.dot && !options.match ? '[A-Za-z0-9_.]' + length : match
25-
26-
return new RegExp(startSpace + '@(' + match + ')' + endSpace, options.flags);
17+
module.exports = function metntionsRegex(dot) {
18+
if (dot) {
19+
// e.g. @google.com will match `google.com`
20+
return /(?:^|[^a-zA-Z0-9_!@#$%&*])(?:(?:@|)(?!\/))([a-zA-Z0-9/_.]{1,15})(?:\b(?!@|)|$)/;
21+
}
22+
// e.g. @google.com will match `google`
23+
return /(?:^|[^a-zA-Z0-9_!@#$%&*])(?:(?:@|)(?!\/))([a-zA-Z0-9/_]{1,15})(?:\b(?!@|)|$)/;
2724
};

0 commit comments

Comments
 (0)