linux:正则表达式
差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录前一修订版 | |||
| linux:正则表达式 [2026/10/13 22:06] – 外部编辑 127.0.0.1 | linux:正则表达式 [2026/10/13 22:51] (当前版本) – 外部编辑 127.0.0.1 | ||
|---|---|---|---|
| 行 15: | 行 15: | ||
| ### - 正常匹配 | ### - 正常匹配 | ||
| - | < | + | |
| + | ```bash | ||
| $ echo "haha [i889" | grep " | $ echo "haha [i889" | grep " | ||
| 行 59: | 行 60: | ||
| $ echo "haha i89" | grep " | $ echo "haha i89" | grep " | ||
| haha i89 | haha i89 | ||
| + | ``` | ||
| + | ### - 匹配非 | ||
| - | + | ```bash | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | ### - 匹配非 | + | |
| - | < | + | |
| $ echo "haha [i8899" | $ echo "haha [i8899" | ||
| haha [i8899 | haha [i8899 | ||
| 像这种情况下,匹配到的是haha [i, 当前行还是被匹配到的。如果不想匹配带89的行,需要在grep的参数加上-v选项。 | 像这种情况下,匹配到的是haha [i, 当前行还是被匹配到的。如果不想匹配带89的行,需要在grep的参数加上-v选项。 | ||
| - | </ | + | ``` |
| ### - grep选中不匹配的行 | ### - grep选中不匹配的行 | ||
| grep -v选项的解释 | grep -v选项的解释 | ||
| - | < | + | |
| + | ``` | ||
| -v, --invert-match | -v, --invert-match | ||
| Invert the sense of matching, to select non-matching lines. | Invert the sense of matching, to select non-matching lines. | ||
| - | </ | + | ``` |
| + | |||
| - | < | + | ```bash |
| $ echo "haha [i8899" | $ echo "haha [i8899" | ||
| + | ``` | ||
| - | </ | ||
| ## - ERE增强 | ## - ERE增强 | ||
| 行 94: | 行 96: | ||
| 注意: | 注意: | ||
| - | < | + | |
| + | ```bash | ||
| $ echo "haha [i889" | grep -E " | $ echo "haha [i889" | grep -E " | ||
| 行 109: | 行 112: | ||
| $ echo "haha) [i889" | grep -E " | $ echo "haha) [i889" | grep -E " | ||
| haha) [i889 | haha) [i889 | ||
| + | ``` | ||
| - | </ | ||
| - | < | + | ``` |
| {n} Match the preceding element if it occurs exactly n times. | {n} Match the preceding element if it occurs exactly n times. | ||
| {n,m} Match the preceding element if it occurs at least n times, but no | {n,m} Match the preceding element if it occurs at least n times, but no | ||
| 行 120: | 行 123: | ||
| {n,} Match the preceding element if it occurs n or more times. | {n,} Match the preceding element if it occurs n or more times. | ||
| {,m} Match the preceding element if it occurs no more than m times. | {,m} Match the preceding element if it occurs no more than m times. | ||
| - | </ | + | ``` |
| 行 126: | 行 130: | ||
| ## - sed命令 | ## - sed命令 | ||
| - | < | + | |
| + | ```bash | ||
| sed ' | sed ' | ||
| 行 139: | 行 144: | ||
| # -i, 将替换后的结果写回原文件中 | # -i, 将替换后的结果写回原文件中 | ||
| sed -i ' | sed -i ' | ||
| - | </ | + | ``` |
linux/正则表达式.1791900372.txt.gz · 最后更改: 由 127.0.0.1
