After sorting out two instances online, you can determine whether there are links in the strings and filter them. You can also directly Delete All hyperlinks in the text. Let's take a look at the instances.
Delete link directly
The Code is as follows: |
Copy code |
/** * Delete hyperconnections in text * @ Param {string} * @ Returns {string} */ DelStrLink: function (str ){ Var htmlreg =/(</? A [^>] *> )(?!. * 1)/ig; // Delete the regular expression used by the hyperjoin. Str = str. replace (htmlreg ,''); Return str; } |
If it is more advanced, we can determine whether the string has links.
The Code is as follows: |
Copy code |
<Script> Var txtContent = 'I'm a few hyperlink http://www.hzhuti.com, http://www.bKjia. c0m/, www.baidu.com '; Var httpReg = new RegExp ("(http [s] {} | ftp): // [a-zA-Z0-9 \. \-] + \. ([a-zA-Z] {2, 4}) (: \ d + )? (/[A-zA-Z0-9 \.\-~! @ # $ % ^ & Amp; * +? : _/= <>] *)? "," Gi "); // used to determine the text content hyperlink // The text address is changed to a link FormatTxtContent = txtContent. replace (httpReg, function (httpText ){ Return '<a href = "' + httpText + '" target = "_ blank">' + httpText + '</a> '; }); Document. write ('original text: '+ txtContent ); Document. write ('<br/> '); Document. write ('formatted text: '+ formatTxtContent ); </Script> |