Linux的ls命令正则表达式,linux之正则表达式(1)

任意建立一个文本并编辑。或者以原有的文本做实验皆可。

$ touch regular_express.txt

$ vi regular_express.txt

//或者 sudo gedit regular_express.txt

操作截图:

a4c26d1e5885305701be709a3d33442f.png

文本内容为:

"Open Source" is a good mechanism to develop programs.

apple is my favorite food.

Football game is not use feet only.

this dress doesn't fit me.

However, this dress is about $ 3183 dollars.

GNU is free air not free beer.

Her hair is very beauty.

I can't finish the test.

Oh! The soup taste good.

motorcycle is cheap than car.

This window is clear.

the symbol '*' is represented as start.

Oh!My god!

The gd software is a library for drafting programs.

You are the best is mean you are the no. 1.

The world <Happy> is the same with "glad".

I like dog.

google is the best tools for search keyword.

goooooogle yes!

go! go! Let's go.

# I am VBird

查找小写字母:

$ grep -n '[[:lower:]]' regular_express.txt

操作截图:

蓝色为匹配成功的字符

a4c26d1e5885305701be709a3d33442f.png

查找数字:

# grep -n '[[:digit:]]' regular_express.txt

操作截图:

a4c26d1e5885305701be709a3d33442f.png

三、语系对正则表达式的影响

由于不同语系的编码数据不同,所以造成不同语系的数据选取结果与所差异。以英文大小写为例,zh_CN.big5 及 C

这两种语系差异如下:

LANG=C 时: 0

1 2 3 4....ABCDE...Zabcde...z

LANG=zh_CN

时:0 1 2 3 4...aAbBcCdD.....zZ

在使用正则表达式[A-Z]时, LANG=C 的情况下,找到的仅仅是大写字符 ABCD..Z。而在 LANG=zh_CN

情况下,会选取到 AbBcCdD.....zZ 字符。因此在使用正则表达式时要特别留意语系。

由于我们一般使用的兼容与 POSIX 的标准,因此使用 C 语系。

四、简单例子 :ls 命令正则表达式应用

ls 命令是 linux 下最常用的命令。ls 命令是 list 的缩写,缺省下 ls 用来打印出当前目录的清单。

命令中‘ * ’号是正则表达式的一种,代表任意字符串。

$ ls

$ ls a* //打印出以 a 开头的文件及内容或者目录

$ ls *s //打印以 s 结尾的文件及内容或者目录

$ ls Pub* // Public 文件为空,所有没有打印任何内容

$ ls e* //没有以 e 开头的文件,所有显示没有找到匹配项

操作截图:

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值