linux常用的正则表达式

参数列表:

^:匹配以指定字符串开头的字符:

cat test.txt | grep ^s

$:匹配以指定字符串结尾的字符:

cat test.txt | grep f$

^$:匹配空行:

cat test.txt | grep -n ^$

[abc]:匹配字符集内任意一个字符:

cat test.txt | grep [^a]

[^abc]:匹配不包含指定字符的字符:

cat test.txt | grep -o  [^a]

匹配非字母的任意行:

cat test.txt | grep [^a-z]

匹配非数字的任意行:

cat test.txt | grep [^0-9]

匹配指定字符出现n次:

cat test.txt | grep -E "a{2}"  || cat test.txt | egrep a{3}

匹配指定字符最少匹配n次或最多匹配m次:

cat test.txt | grep -E "a{1,2}d"

匹配指定字符出现至少n次:

cat test.txt | grep -E "a{1,}"

匹配以指定字符开头以指定字符结尾的字符:

cat test.txt  | grep s.*k
posted @   草原悍匪  阅读(85)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示