免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2046 | 回复: 5
打印 上一主题 下一主题

请教POSIX的括号表达式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-21 01:12 |只看该作者 |倒序浏览
POSIX的括号表达式中,字符类[::]是经常用到的,等价类[==]通过测试也已了解,但一直没有搞明白整理符号[..]的意义和用法。
例如sed&awk里面提到的[[.ch.]],我用grep、awk --posix都试过,但都直接报错,不知道什么时候才能用到。
还有就是[[.ch.]]和直接ch有什么区别?
望各位高手不吝赐教。

论坛徽章:
0
2 [报告]
发表于 2009-05-21 11:23 |只看该作者
不是很清楚[:foo:],[=foo=]和[.foo.]有什么区别

论坛徽章:
0
3 [报告]
发表于 2009-05-21 11:31 |只看该作者
原帖由 justlooks 于 2009-5-21 11:23 发表
不是很清楚[:foo:],[=foo=]和[.foo.]有什么区别

[:foo:]比较常见,就是用一些特定名称表示一定的字符范围;
[=foo=]是处理地区化字符的方式,例如法语里的"à"可以用[[=a=]]匹配到;
[.foo.]说是表示字符序列,例如[[.ch.]],不会匹配c或h,只会匹配ch,但我没搞明白这和直接用ch匹配有什么区别,也没找到在什么地方可以用这么个表达式……

论坛徽章:
0
4 [报告]
发表于 2009-05-21 11:32 |只看该作者
刚好正在看gawk,复制下来相关原文吧.

Collating symbols
Multicharacter collating elements enclosed between ‘[.’ and ‘.]’. For example,
if ‘ch’ is a collating element, then [[.ch.]] is a regexp that matches this
collating element, whereas [ch] is a regexp that matches either ‘c’ or ‘h’.

Equivalence classes
Locale-specific names for a list of characters that are equal. The name is enclosed
between ‘[=’ and ‘=]’. For example, the name ‘e’ might be used to represent
all of “e,” “`e,” and “′e.” In this case, [[=e=]] is a regexp that matches
any of ‘e’, ‘′e’, or ‘`e’.

These features are very valuable in non-English-speaking locales.

Caution: The library functions that gawk uses for regular expression matching currently
recognize only POSIX character classes; they do not recognize collating symbols or equivalence
classes.

论坛徽章:
0
5 [报告]
发表于 2009-05-21 11:39 |只看该作者
http://blog.chinaunix.net/u/634/showart.php?id=2466

感谢楼上2位
[:] x 是 character class
Standard  character class有
alnum       digit       punct
alpha       graph       space
blank       lower       upper
cntrl       print       xdigit
[=x=]  x是equivalence classes
这个应该是用在处理不同locale字符的
[.x.] x可以是多个字符,作为一个整体来匹配的

以上是我的理解

我的grep 是2.5.3可以支持 equivalence classes

[ 本帖最后由 justlooks 于 2009-5-21 11:54 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2009-05-21 11:47 |只看该作者
原帖由 justlooks 于 2009-5-21 11:39 发表
http://blog.chinaunix.net/u/634/showart.php?id=2466

貌似从表上看awk,grep 都不支持 collating symbols or equivalence classes ,但sed好像支持collating symbols,不过我没试出来

呃,不知道为啥BLOG链接点不开~前两天晚上在家上论坛貌似也堵了好久,CU服务器的问题么?……
sed我也试过,也没试出来~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP