SoFunction
Updated on 2025-03-10

A thorough analysis of regular expressions and wildcard characters

1. Special symbols

''    What you see is what you get
""     Special symbols will be parsed and run
``     == $() Run the command inside first and leave the result
>
>>    Append redirection          Append file's last
2>    Error redirection          Only the wrong information will enter the file through this vulnerability
2>>   Error appending redirection
~      The current user's home directory
!      Find and run historical commands
!awk  The command containing awk The most recent run
      history |grep awk
#      Comments
The root user's command prompt
$      Take out the contents of the variable
awk $ Take the content of a certain column
Command prompt for ordinary users
*        Everything
\      Crowbar Escape Character
&&     The previous command is executed successfully and then the next command is executed
      ifdown eth0 && ifup eth0

||     If the previous command fails to support it, then execute the following command

2. Wildcard

Wildcards are used to find files.

2.1. All, any*

2.2.{} Generate sequence

3. Regular expressions

3.1.What is regularity? Why use it?

The text content is represented by symbols.

Improve efficiency and save trouble.

3.2. Things to note when using regular

Regular expressions are processed by rows

Chinese symbols are prohibited

Configure alias for grep and egrep

cat >>/etc/profile<<EOF
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
EOF
source /etc/profile

3.3. The difference between regular expressions and wildcards

Purpose

Wildcards---used to match the search file name      *.txt *.log Files ending in .txt .log Most commands can be used

Regular ------Match the search content in the file. Lines containing abc.

3.4. Regular Expression Classification

Basic Regularity         ^ $ . * []  [^]      basic    regular expression BRE   grep                                                                                                                                                                                                                                 �

Extended Regularity      | +   {} () ?      extended   regular expression ERE  grep -E/egrep  sed -r awk

3.5. Regular expression summary

Continuous occurrence (repeat)

     *        >=0
            +        >=1
            ?        0 1
            {n,m}    >=n  <=m
            {n}      ==n
other
Any character
[abc]     A whole is equivalent to a character
                     [a-z] [0-9] [A-Z]
[^abc]   Exclude
|
() Backward reference Backward reference Protect first and then use
            ^
            $
.* all
^$

3.6. The difference between basic and extended regularities

grep                    egrep === grep -E
sed                     sed -r
awk                     awk

This is the article about the introduction of regular expressions and wildcards and differences. For more related regular expressions, please search for my previous articles or continue browsing the related articles below. I hope you will support me in the future!