Debian Codegraph @

src/matcher/Email.js

raw symbols SCIP
1 /*global Autolinker */
2 /**
3 * @class Autolinker.matcher.Email
4 * @extends Autolinker.matcher.Matcher
5 *
6 * Matcher to find email matches in an input string.
7 *
8 * See this class's superclass ({@link Autolinker.matcher.Matcher}) for more details.
9 */
10 Autolinker.matcher.Email = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
11
12 /**
13 * The regular expression to match email addresses. Example match:
14 *
15 * [email protected]
16 *
17 * @private
18 * @property {RegExp} matcherRegex
19 */
20 matcherRegex : (function() {
21 var alphaNumericChars = Autolinker.RegexLib.alphaNumericCharsStr,
22 specialCharacters = '!#$%&\'*+\\-\\/=?^_`{|}~',
23 restrictedSpecialCharacters = '\\s"(),:;<>@\\[\\]',
24 validCharacters = alphaNumericChars + specialCharacters,
25 validRestrictedCharacters = validCharacters + restrictedSpecialCharacters,
26 emailRegex = new RegExp( '(?:[' + validCharacters + '](?:[' + validCharacters + ']|\\.(?!\\.|@))*|\\"[' + validRestrictedCharacters + '.]+\\")@'),
27 getDomainNameStr = Autolinker.RegexLib.getDomainNameStr,
28 tldRegex = Autolinker.tldRegex; // match our known top level domains (TLDs)
29
30 return new RegExp( [
31 emailRegex.source,
32 getDomainNameStr(1),
33 '\\.', tldRegex.source // '.com', '.net', etc
34 ].join( "" ), 'gi' );
35 } )(),
36
37
38 /**
39 * @inheritdoc
40 */
41 parseMatches : function( text ) {
42 var matcherRegex = this.matcherRegex,
43 tagBuilder = this.tagBuilder,
44 matches = [],
45 match;
46
47 while( ( match = matcherRegex.exec( text ) ) !== null ) {
48 var matchedText = match[ 0 ];
49
50 matches.push( new Autolinker.match.Email( {
51 tagBuilder : tagBuilder,
52 matchedText : matchedText,
53 offset : match.index,
54 email : matchedText
55 } ) );
56 }
57
58 return matches;
59 }
60
61 } );