File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change 8
8
'use strict' ;
9
9
10
10
/**
11
- * The correct mention(s) regex. Regex done right!
11
+ * Compatible twitter mentions regex
12
12
*
13
- * @param {Object } `options`
13
+ * @param {Boolean } `dot` if `true` it will allow to match dots
14
14
* @return {RegExp }
15
+ * @api public
15
16
*/
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 - z A - Z 0 - 9 _ @ ! @ # $ % & * ] ) (?: (?: @ | @ ) (? ! \/ ) ) ( [ a - z A - Z 0 - 9 / _ . ] { 1 , 15 } ) (?: \b (? ! @ | @ ) | $ ) / ;
21
+ }
22
+ // e.g. @google .com will match `google`
23
+ return / (?: ^ | [ ^ a - z A - Z 0 - 9 _ @ ! @ # $ % & * ] ) (?: (?: @ | @ ) (? ! \/ ) ) ( [ a - z A - Z 0 - 9 / _ ] { 1 , 15 } ) (?: \b (? ! @ | @ ) | $ ) / ;
27
24
} ;
You can’t perform that action at this time.
0 commit comments