Home > Web Front-end > JS Tutorial > Regular metacharacters and ordinary characters

Regular metacharacters and ordinary characters

php中世界最好的语言
Release: 2018-03-29 10:53:09
Original
1683 people have browsed it

This time I will bring you regular metacharacters and ordinary characters. What are the precautions when using regular metacharacters and ordinary characters? The following is a practical case. Let’s take a look. take a look.

If you want to learn regular expressions, understanding metacharacters and ordinary characters is a difficulty that must be overcome. No need to remember it deliberately. The editor below brings you knowledge about regular expression metacharacters and ordinary characters, let’s take a look.

According to the regular expression grammar rules, the matching pattern of the regular expression is composed of a series of characters.

1. Ordinary characters:

Most characters can only describe themselves. These characters are called ordinary characters, such as all letters. and numbers.

That is to say, ordinary characters can only match the same characters in string.

2. Metacharacters:

Since ordinary characters can only match the same characters as themselves, the flexibility and power of regular expressions The matching function cannot be fully displayed, so the regular expression specifies a series of special characters . These characters are not matched according to the direct quantity of characters, but have special semantics,

For example, the following characters:

^ $ . * + ? = ! : | \ / ( ) [ ] { }
Copy after login

Although the above characters have special meanings, some characters only have special meanings in certain contexts.

If you want to match these character literals with special meanings, you need to add a backslash (\) in front of these characters to escape. For example, if I want to match a $ literal, I need to write it as \$, otherwise it will match. An ending position. It is precisely because of the existence of these special characters that regular expressions have powerful functions.

Because they are the basic characters for constructing various regular expressions that match complex text, they are called metacharacters.

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:

Use regular expressions to filter email mailboxes/email addresses

vue2.0 axios cross-domain and What should you pay attention to when rendering?

How does Vue.js realize the function of dragging pictures at will

The above is the detailed content of Regular metacharacters and ordinary characters. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template