42 lines
1.1 KiB
Markdown
42 lines
1.1 KiB
Markdown
|
### 部分概念
|
||
|
- 元字符:在正则表达式中具有特殊意义的字符,如星号(*)、问号(?)和点(.)
|
||
|
- 前导字符:位于元字符前边的第一个字符
|
||
|
|
||
|
### 其他常用元字符
|
||
|
![9c89f9daed2d117cc3247a5e5a72cf1c.png](../../_resources/9c89f9daed2d117cc3247a5e5a72cf1c.png)
|
||
|
```
|
||
|
me@me-EQ59:~/shell_demo$ cat hello_grep.txt
|
||
|
hello world
|
||
|
|
||
|
hello hello
|
||
|
me@me-EQ59:~/shell_demo$ grep '\<hel' hello_grep.txt
|
||
|
hello world
|
||
|
hello hello
|
||
|
me@me-EQ59:~/shell_demo$ grep 'lo\>' hello_grep.txt
|
||
|
hello world
|
||
|
hello hello
|
||
|
me@me-EQ59:~/shell_demo$
|
||
|
```
|
||
|
|
||
|
```
|
||
|
me@me-EQ59:~/shell_demo$ grep '\d' hello_grep.txt
|
||
|
hello world
|
||
|
me@me-EQ59:~/shell_demo$ grep -P '\d' hello_grep.txt
|
||
|
10.1.1.1
|
||
|
me@me-EQ59:~/shell_demo$ cat hello_grep.txt
|
||
|
hello world
|
||
|
|
||
|
hello hello
|
||
|
10.1.1.1
|
||
|
me@me-EQ59:~/shell_demo$
|
||
|
```
|
||
|
|
||
|
|
||
|
### 扩展正则
|
||
|
- grep 使用需要加参数 `-E` 或者使用 egrep
|
||
|
- sed 使用需要加参数 `-r`
|
||
|
![25e2449631afbce54c6b4f757aae82db.png](../../_resources/25e2449631afbce54c6b4f757aae82db.png)
|
||
|
|
||
|
|
||
|
### 第二类正则
|
||
|
![2f4d02d4c9263d854c2f7d8adf177139.png](../../_resources/2f4d02d4c9263d854c2f7d8adf177139.png)
|