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

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-12 13:31:17

/i: case-insensitive.
/s: any character including newline.
  1. $_ = "I saw Barney\ndown at the bowling alley\nwith Fred\nlast night.\n";
  2. if (/Barney.*Fred/s) {
  3.   print "That string mentions Fred after Barney!\n";
  4. }
/x: allows you to add arbitrary whitespace to a pattern to
/m: multiple-line text;
  1. open FILE, "re_.pl" or die " can not open\n";
  2. $_ = join '', <FILE>;
  3. s/^/test:/gm;
  4. print ;
add test: to the beginning of every line.

make it easier to read:
/-?\d+\.?\d*/         # what is this doing?
/ -? \d+ \.? \d* /x   # a little better
(^) marks the beginning of the string, while the dollar sign ($) marks
the end.
The word-boundary anchor, \b, matches at either end of a word.‡ So you can use /\bfred\b/ to match the word fred but not frederick or alfred or manfred mann.

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