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

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-13 09:36:19

  1. Suppose you’re using
  2. the pattern /fred.+barney/ on the string fred and barney went bowling last night.
the .+ is greedy. it will match all of the rest string including night. then give back t, h, and so on until barney to match barney.

For each of the greedy quantifiers, though, there’s also a nongreedy quantifier available.
Instead of the plus (+), we can use the nongreedy quantifier +?, which matches one or
more times (just as the plus does), except that it prefers to match as few times as pos-
sible
, rather than as many as possible.
if we use /fred.+?barney/. it will match the whitespace and then try to match barney, it can not match, so match a and try again to match barney but with no success, it will try until match barney.

  1. $str = "I thought you said Fred and Velma, not Wilma";

  2. $str =~ s#<BOLD>(.*?)</BOLD>#$1#g;
  3. print $str;
I thought you said Fred and  Velma, not  Wilma

阅读(343) | 评论(0) | 转发(0) |
0

上一篇:split join

下一篇:find install modules

给主人留下些什么吧!~~