2021-03-02 13:02:56 +02:00
|
|
|
import regexSupplant from 'twitter-text/dist/lib/regexSupplant';
|
|
|
|
import validDomain from 'twitter-text/dist/regexp/validDomain';
|
|
|
|
import validPortNumber from 'twitter-text/dist/regexp/validPortNumber';
|
|
|
|
import validUrlPath from 'twitter-text/dist/regexp/validUrlPath';
|
2023-05-28 17:38:10 +03:00
|
|
|
import validUrlPrecedingChars from 'twitter-text/dist/regexp/validUrlPrecedingChars';
|
2021-03-02 13:02:56 +02:00
|
|
|
import validUrlQueryChars from 'twitter-text/dist/regexp/validUrlQueryChars';
|
|
|
|
import validUrlQueryEndingChars from 'twitter-text/dist/regexp/validUrlQueryEndingChars';
|
2017-09-16 16:01:15 +03:00
|
|
|
|
2021-03-02 13:02:56 +02:00
|
|
|
// The difference with twitter-text's extractURL is that the protocol isn't
|
|
|
|
// optional.
|
2017-09-16 16:01:15 +03:00
|
|
|
|
2021-03-02 13:02:56 +02:00
|
|
|
export const urlRegex = regexSupplant(
|
|
|
|
'(' + // $1 URL
|
|
|
|
'(#{validUrlPrecedingChars})' + // $2
|
|
|
|
'(https?:\\/\\/)' + // $3 Protocol
|
|
|
|
'(#{validDomain})' + // $4 Domain(s)
|
|
|
|
'(?::(#{validPortNumber}))?' + // $5 Port number (optional)
|
|
|
|
'(\\/#{validUrlPath}*)?' + // $6 URL Path
|
|
|
|
'(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?' + // $7 Query String
|
|
|
|
')',
|
|
|
|
{
|
|
|
|
validUrlPrecedingChars,
|
|
|
|
validDomain,
|
|
|
|
validPortNumber,
|
|
|
|
validUrlPath,
|
|
|
|
validUrlQueryChars,
|
|
|
|
validUrlQueryEndingChars,
|
|
|
|
},
|
|
|
|
'gi',
|
|
|
|
);
|