Created
July 30, 2018 02:08
-
-
Save phuochau/e42f28bd77df26d55532aeca12dacac1 to your computer and use it in GitHub Desktop.
[JS] Detect links and replace link by another string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const hasLinks = (str) => { | |
| return str.test(/(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi) | |
| } | |
| export const groupLinkIntoAngleBracket = (str, replacedString) => { | |
| return str.replace(/(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi, replacedString) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment