免费注册 查看新帖 |

Chinaunix

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

关于back reference的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-06 14:11 |只看该作者 |倒序浏览
在研读精华贴的过程中,发现如下内容:

If the group doesn't participate in a match, i.e., it is part of an
alternative not taken or a repetition operator allows zero
repetitions of it, then the back reference makes the whole match
fail. For example, `(one()|two())-and-(three\2|four\3)' matches
`one-and-three' and `two-and-four', but not `one-and-four' or
`two-and-three'. For example, if the pattern matches `one-and-',
then its group 2 matches the empty string and its group 3 doesn't
participate in the match. So, if it then matches `four', then
when it tries to back reference group 3--which it will attempt to
do because `\3' follows the `four'--the match will fail because
group 3 didn't participate in the match.

百思不得其解    ,在Solaris bash环境中测试也未得结果,请大家帮忙解释一下,多谢多谢!
# cat tmp
one-and-three
two-and-four
one-and-four
two-and-three
# grep '\(one\(\)|two\(\)\)-and-\(three\2|four\3\)' tmp
#

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2005-09-06 14:34 |只看该作者

关于back reference的问题

grep -E '(one()|two())-and-(three\2|four\3)' tmp

论坛徽章:
0
3 [报告]
发表于 2005-09-06 14:43 |只看该作者

关于back reference的问题

[quote]原帖由 "waker"]grep -E '(one()|two())-and-(three\2|four\3)' tmp[/quote 发表:


这个我也试过了,也是没有任何输出结果,真奇怪!

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2005-09-06 14:51 |只看该作者

关于back reference的问题

没有sunbox,在linux下是可以的GNU grep2.5.1

论坛徽章:
0
5 [报告]
发表于 2005-09-06 14:59 |只看该作者

关于back reference的问题

[quote]原帖由 "waker"]没有sunbox,在linux下是可以的GNU grep2.5.1[/quote 发表:


果然,谢谢waker。我再查查solaris的man。另外,one和two后面的()是什么意思呀?

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
6 [报告]
发表于 2005-09-06 15:05 |只看该作者

关于back reference的问题

group 2 matches the empty string
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP