Code for converting text into hyper-connection and Email format

Source: Internet
Author: User

If the user enters a http://aaa.bbb.ccc
The code below will convert his input into a http://aaa.bbb.ccc
Let's see how powerful regular expressions are.

<%
'Call this function to display the result as a hyperjoin.
Response. Write to_html (s_message)
%>


<%
Function to_html (s_string)
To_html = Replace (s_string ,"""",""")
To_html = Replace (to_html, "<", "<")
To_html = Replace (to_html, ">", "> ")
To_html = Replace (to_html, vbcrlf, "<br> ")
To_html = Replace (to_html, "/<", "<")
To_html = Replace (to_html, "/>", "> ")
To_html = edit_hrefs (to_html)
End Function
%>

<Script language = "javascript1.2" runat = server>
Function edit_hrefs (s_html ){
// A model using regular expressions
// Convert all the superlinks and email formats in the text
S_str = new String (s_html );

S_str = s_str.replace (/bhttp: // www (. [w +.:/_] +)/gi,
"Http: // commandid scheme $1 ");

S_str = s_str.replace (/B (http: // w +. [w +.:/_] +)/gi,
"<A href =" $1 "> $1 </a> ");

S_str = s_str.replace (/B (www. [w +.:/_] +)/gi,
"<A href =" http: // $1 ">1 1 </a> ");

S_str = s_str.replace (/bhttp: // zookeeper callback (. [w +.:/_] +)/gi,
"<A href =" http: // www $1 "> http: // www $1 </a> ");

S_str = s_str.replace (/B (w + @ [w +.?] *)/Gi,
"<A href =" mailto: $1 ">1 1 </a> ");


Return s_str;
}
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.