Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common characters of basic regular expressions and extended regular expressions

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what characters are commonly used in basic regular expressions and extended regular expressions. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The so-called regular expression is to use a class of metacharacters (not to express their own meaning, but to express unified or other meanings), groups.

If it is compiled with other characters, it can match the qualified characters.

There are two types of regular expressions: basic regular expressions and extended regular expressions.

Basic regular expression:

^ anchoring eligible content at the beginning of a line

$anchoring eligible content at the end of a line

^ $represents a blank line

. Match any single character

* match the character in front of it any number of times

. * match any character of any length

[] matches any character within the specified range

[^] matches any character outside the specified range

\? Match the word immediately in front of it 0 or 1 times

\ {mdirection n\} matches the characters preceding them at least m times and n times at most

\ {0menent n\} matches the character preceding it 0mern times

\ {m,\} match the characters preceding them at least m times

\ {m\} exact match m times

\

< 锚定词首 \>

Anchor suffix

Group\ (\)

Common options for grep

-- color=auto automatically adds colors to matching characters

-v reverse selection, showing only lines that do not match the pattern

-o displays only the strings that can be matched by the pattern, not the entire line

-I is not case-sensitive

When-A n displays the matching rows, the n rows following them are displayed by the way.

-B n displays the front n lines

-C n displays the next n lines

-E uses the extended regular expression grep-E = egrep

Extend regular expressions (here to list the differences)

? The regular expression appears 0 times or 1 time.

{mdirection n} matches the leading characters at least m times and n times at most

() grouped, which is similar to grep

A | b choose one of the two

1. Anchor the line beginning with root in the / etc/passwd file

Grep "^ root" / etc/passwd

2. Anchor the line ending with sh in the / etc/passwd file

Grep "sh$" / etc/passwd

3, find a blank line

Grep "^ $" / etc/passwd

4, matches a line followed by any single character

Grep "a." / etc/passwd

5, matches a line followed by characters of any length

Grep "a *" / etc/passwd

4, match a followed by any character of any length, followed by the line of b

Grep "a.pragb" / etc/passwd

5, match a followed by any number followed by any letter line

Grep "a [0-9] [a-zA-Z]" / etc/passwd

6, matches a line followed by any number or letter

Grep "a [0-9a-zA-Z]" / etc/passwd

7, matches 0 or 1 a followed by a b line

Grep "a\? B" / etc/passwd

8, match at least one a, and at most 3 a followed by a b line

Grep "a\ {1mer3\} b" / etc/passwd

9, anchor the line of the word admin

Grep "\" / etc/passwd

10. Match rows with ad at least once and ad at most 3 times

Grep "\ (ab\)\ {1pm 3\}" / etc/passwd

This is the end of this article on "what characters are commonly used in basic regular expressions and extended regular expressions". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report