全字匹配的正则表达式怎么写?

sh/bash/dash/ksh/zsh等Shell脚本
回复
crossie
帖子: 241
注册时间: 2008-05-25 20:35

全字匹配的正则表达式怎么写?

#1

帖子 crossie » 2008-07-18 10:25

就是想匹配
this is cool
里的cool
而不匹配
this is cooler

还有,匹配中文的正则表达式怎么写?

谢谢
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2008-07-18 10:28

\< \> \B \b
中文的是一个范围 \uxxxx-\uxxxx 不记得具体的了。
● 鸣学
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

Re: 全字匹配的正则表达式怎么写?

#3

帖子 kofshower » 2008-07-18 10:30

crossie 写了:就是想匹配
this is cool
里的cool
而不匹配
this is cooler

还有,匹配中文的正则表达式怎么写?

谢谢
cool\b
中文的话[^[:print:]]
喔喔 刚刚实验了下
要加LANG=zh_CN.gbk
或是LANG=C
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
crossie
帖子: 241
注册时间: 2008-05-25 20:35

#4

帖子 crossie » 2008-07-18 10:43

eexpress 写了:\< \> \B \b
中文的是一个范围 \uxxxx-\uxxxx 不记得具体的了。
谢谢

有人说匹配中文的 \u4e00 \u9fa5
我试过不行...
上次由 crossie 在 2008-07-18 10:52,总共编辑 2 次。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#5

帖子 eexpress » 2008-07-18 10:45

你应该马上 man 啊。 \B 是反向的哦。@@@
● 鸣学
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#6

帖子 kofshower » 2008-07-18 11:02

要是中文里面正好碰到回车怎么办?这个问题很诡异,刚刚看了下中文的正则。建议不要做中文正则式的替换之类的操作,可能会乱码。我是说和shell里面命令所使用的正则库有关
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
头像
greco
帖子: 2487
注册时间: 2007-04-06 10:24
来自: ~/Shanghai

#7

帖子 greco » 2008-07-18 11:20

(?:^|\b)YourKeyWord(?:^|\b)
http://silenceisdefeat.com/~greco

代码: 全选

''.join([chr(ord(c)-2) for c in 'O{"G/ockn"ku<"itgeq0ujkBiockn0eqo'])
echo -n "Z3JlY28uc2hpQGdtYWlsLmNvbQ==" | base64 -d
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

#8

帖子 xiooli » 2008-07-18 11:46

grep -w ? :shock:
头像
79hy
帖子: 80
注册时间: 2007-10-24 10:21
来自: 长沙

#9

帖子 79hy » 2008-07-22 11:05

xiooli 写了:grep -w ? :shock:
这个方法正点~~~
头像
zcg0696
帖子: 44
注册时间: 2008-05-27 17:30

#10

帖子 zcg0696 » 2008-07-27 0:10

中文匹配[^\x00-\x80]+
回复