Control 360 Browser default fast mode with META tag to open your website and regular expressions

Source: Internet
Author: User

Add a line of code to the head tag:

<meta name= "renderer" content= "Webkit|ie-comp|ie-stand" >
<body>
</body>

Content value is one of webkit,ie-comp,ie-stand, case-sensitive, respectively, represented by the WebKit kernel, IE compatible kernel, IE standard kernel.

If the page needs to be the default speed core, add tag: <meta name= "renderer" content= "WebKit" >

If the page needs to default IE compatible kernel, add tag: <meta name= "renderer" content= "Ie-comp" >

If the page needs to default with IE standard kernel, add tag: <meta name= "renderer" content= "Ie-stand" >

Note: Quotation marks to the English state, the direct copy of the code to see the format is right, please correct yourself.

Define the Regular:

Copy the code code as follows:

var re = new RegExp ("a"); The RegExp object. Parameters are the rules we want to make. There is a situation that must be used in this way, as mentioned below.
var re =/a/; The shorthand method recommends the use of better performance can not be empty or you think it is a comment,

Common methods of regular

1 Test (): Finds the content in the string that conforms to the regular, and returns False if the lookup returns TRUE.

Usage: Regular. Test (String)

Example: Judging whether it is a number

var str = ' 374829348791 ';
var re =/\d/; \d represents non-digital
if (Re.test (str)) {//returns True, representing a non-number found in the string.
Alert (' Not all numbers ');
}else{
Alert (' all numbers ');
}

There are many symbols in regular expressions that represent different meanings that we can use to define different rules, such as the \d above, and the following:

\s: Space
\s: Non-whitespace
\d: Digital
\d: Non-digital
\w: Characters (Letters, numbers, underscores _)

\w: Non-character Example: whether there are characters that are not numbers

(The following will be based on examples, in turn, some of the commonly used characters, and finally summarized.) )

2 search (): Search for regular content in a string, search to return to the location of the occurrence (starting from 0, if the match is not just a letter, that will only return the position of the first letter), if the search failed to return-1

Usage: string. Search (Regular)

Finds the contents of a compound regular in a string. Ignore case: I――ignore (the default in regular is case-sensitive, if case insensitive, at the end of the regular ID i)

Example: Finding the letter B in a string with case-insensitive

var str = ' abcdef ';
var re =/b/i;
var re = new RegExp (' B ', ' I '); Can also be written like this
Alert (Str.search (re)); 1
3 match () searches the string for the contents of the compound rule, returns the content when the search succeeds, formats an array, and returns null if it fails.
Usage: string. Match (Regular)
Quantifier: + At least one occurrence of an indeterminate number of times (matching is the meaning of search lookup)

Global match: G――global (the default in regular, as long as the search for the contents of the compound rule will end the search)

Example: Find all numbers in the specified format, as found below 123,54,33,879

Copy the code code as follows:

var str = ' haj123sdk54hask33dkhalsd879 ';
var re =/\d+/g; Matches at least one number at a time and the global match if it is not a global match, it will stop when the number 123 is found. It just pops up. 123. With a global match, the search is consistent from start to finish. If there is no plus, the result of the match is that 1,2,3,5,4,3,3,8,7,9 is not what we want, and with the plus sign, the number that matches each time is at least one.
Alert (Str.match (re)); [123,54,33,879]

4 replace (): Finds a string that matches the regular character and replaces it with the corresponding string. Returns the content after the replacement.

Usage: string. Replace (regular, new string/callback function) (in the callback function, the first parameter refers to the character that each match succeeds)

| : or the meaning.

Example: Sensitive word filtering, such as I love Beijing Tian ' an gate, the sun rises in Tiananmen Square. ------I love *****,**** on the sun rise. That is, Beijing and Tiananmen become * numbers,

At first we might think of such a method:

var str = "I love Beijing Tian An men, the sun rises on Tiananmen Square." ";
var re =/Beijing | Tiananmen/g; Find Beijing or Tiananmen Global match
var str2 = str.replace (Re, ' * ');
Alert (STR2)//I love **,* on the sun rising
This just turns the found into a *, and cannot be a few words corresponding to a few *.

To implement a few words corresponding to several *, we can use the callback function to implement:

Copy the code code as follows:

var str = "I love Beijing Tian An men, the sun rises on Tiananmen Square." ";
var re =/Beijing | Tiananmen/g; Find Beijing or Tiananmen Global match
var str2 = str.replace (re,function (str) {
alert (str); Used to test: the first parameter of the function represents each search to match the regular character, so the first STR refers to the second STR in Beijing is the third time Str is Tiananmen Square
var result = ';
for (Var i=0;i<str.length;i++) {
Result + = ' * ';
}
return result; So search for a few words to return a few *
});
Alert (STR2)//I love *****,*** on the sun rising
The whole process is to find Beijing, replaced by two *, find Tiananmen Square replaced by 3 *, find Tiananmen Square replaced by 3 *.

Replace is a useful method that is often used.

The characters in the regular

():, parentheses, called a group character. is equivalent to the parentheses in mathematics. As follows:

Copy the code code as follows:

var str = ' 2013-6-7 ';
var re1 =/\d-+/g; Global match number, horizontal bar, the number of bars is at least 1, matching result is: 3-6-
var Re1 =/(\d-) +/g; Globally matched numbers, bars, numbers and bars with a total number of at least 1 3-6-
var Re2 =/(\d+) (-)/g; Globally matches at least one number, matching a cross-bar match result: 2013-6-

At the same time, each parenthesized item in the regular is called the regular subkey. Children are very useful at some point, for example, we look at a chestnut.

Control 360 Browser default fast mode with META tag to open your website and regular expressions

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.