Detailed explanation of the use of . metacharacter in regular expressions (with code)

php中世界最好的语言
Release: 2018-03-30 11:48:55
Original
2009 people have browsed it

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));
Copy after login

The above code can match all characters in the string.

Example 2:

var str="antzone<123"; var reg=/.+/; console.log(str.match(reg));
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!