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