This time I will bring you a detailed explanation of the use of the . sign metacharacter inregular expressions(with code). What are theprecautionswhen using the . sign metacharacter in regular expressions? The following is a practical case, let’s take a look.
Regular expression. sign metacharacter:
The dot (.) metacharacter can match characters other than carriage return (\r) and line feed (\n) Any character.
Syntax structure:
Constructor functionMethod:
new RegExp(".")
Direct object method:
[JavaScript] Plain text view copy code run code
/./
Browser support:
IE browser supports this metacharacter.
Firefoxsupports this metacharacter.
Google Chrome supports this metacharacter.
Note:
In IE9 or above browsers or other standard browsers, the decimal point can match except carriage return (\r) and line feed (\n) Any character other than .
In browsers below IE8, the decimal point can match any character except the newline character (\n).
Example code:
Example 1:
var str="antzone<123"; var reg=new RegExp(".+"); console.log(str.match(reg));
The above code can match all characters in the string.
Example 2:
var str="antzone<123"; var reg=/.+/; console.log(str.match(reg));
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of the three modes of regularity (greedy, reluctant, possessive)
How to use it in JS Regularity replaces multiple spaces in a string with one space,
The above is the detailed content of Detailed explanation of the use of . metacharacter in regular expressions (with code). For more information, please follow other related articles on the PHP Chinese website!