Chinaunix首页 | 论坛 | 博客
  • 博客访问: 838213
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-12 14:37:57

if we use the parentheses in the RE, it will store the matched string to the memory. the first parentheses' string stored to $1 the second to $2 and so on. if we don't use the matched string, we can use ?: to ignore the matched one.

  1. if (/(?:bronto)?saurus (steak|burger)/) {
  2.     print "Fred wants a $1\n";
  3. }
even if we add something to the RE, it will not change the group number
  1. if (/(?:bronto)?saurus (?:BBQ )?(steak|burger)/) {
  2.     print "Fred wants a $1\n";
  3. }

阅读(360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~