Write a simple chat system and send an Htpp Url to add the tag. The following is a specific implementation. Do not miss it if you are interested.
Background:Write a Simple Chat System and issue an Htpp Url to add the tag.
Implementation Code:
The Code is as follows:
String. prototype. httpHtml = function (){
Var reg =/(http: \/| https: \/) (\ w | = | \? | \. | \/| & |-) +)/G;
Return this. replace (reg, '$1 $2 ');
};
Excerpt:
Implementation of Automatic Adding of URL addresses
The implementation of automatic adding of URL addresses is actually something: Detection and replacement.
Detection
"Detection" is to check whether the text (string) contains content that conforms to the http address. Obviously, this requires regular expression verification. This can be done at the front end and back end. Here, only the front-end method is used for implementation in JavaScript.
The regular expression used to verify the HTTP address is as follows (which may be incorrect or inaccurate ):
Var reg =/(http: \/| https: \/) (\ w | = | \? | \. | \/| & |-) +)/G;
The first part matches the URL string address starting with http or https. The latter part matches some characters, including English characters, underscores (_), periods (.), and question marks (?) And equal signs (=), short connections (-), etc.
Replace
When it comes to the replacement function in JavaScript, the first thing that comes to mind is the replace attribute. The powerful feature of the replace attribute is that it supports regular expressions and can replace regular strings. For example, to replace the spaces at both ends of a string, you can use a statement similar to the following:
The Code is as follows:
Var s = "blank ";
S = s. replace (/^ \ s + (.*?) \ S + $ /,"");
Alert (s );