5:However, this dress is about $
3183
dollars.
15:You are the best is mean you are the no.
1
.
但由于考虑到语系对于编码顺序的影响,因此除了连续编码使用减号『
-
』之外,
你也可以使用如
下的方法来取得前面两个测试的½果:
[dmtsai@study ~]$
grep
-
n '[^[:lower:]]oo' regular_express.txt
#
那
个
[:lower:]
代表的就是
a
-
z
的意思!
请参
考前
两
小
½
的
说
明表格
[dmtsai@study ~]$
grep
-
n '[[:digit:]]' regular_express.txt
啥?上头在写啥东西呢?不要害怕!分开来瞧一瞧。我们知道
[:lower:]
就是
a-z
的意思,那么
[
a-z
]
当然就是
[
[:lower:]
]
啰!鸟哥第一次½触正规表示法的时候,看到两层中括号差点昏倒~完全看不
懂!现在,请注意那个迭代的意义,
自然就能够比½清楚了½啰!
这样对于
[]
以及
[^]
以及
[]
当中的
-
,还有关于前面表格提到的特殊关键词有了½了吗?
^_^
!
.
例题三、行首与行尾字符
^ $
我们在例题一当中,可以查询到一行字符串里面有
the
的,那如果我想要让
the
只在行首列出呢?
这个时候就得要使用制表符了!我们可以这样做:
[dmtsai@study ~]$
grep
-
n '^the' regular_express.txt
12:
the
symbol '*' is represented as start.
此时,就只剩下第
12
行,因为只有第
12
行的行首是
the
开头啊~此外,
如果我想要开头是小写
字符的那一行就列出呢?可以这样:
[dmtsai@study ~]$
grep
-
n '^[a
-
z]' regular_express.txt
2:
a
pple is my favorite food.
4:
t
his
dress doesn't fit me.
10:
m
otorcycle is cheap than car.
12:
t
he symbol '*' is represented as start.
18:
g
oogle is the best tools for search keyword.
19:
g
oooooogle yes!
20:
g
o! go! Let's go.
你可以发现我们可以捉到第一个字符都不是大写的!上面的指令也可以用如下的方式来取代的:
[dmtsai@study ~]$
grep
-
n
'^[[:lower:]]' regular_express.txt
好!那如果我不想要开头是英文字母,则可以是这样: