#!/perl
use strict;
my ($var);
$var = "I saw Barney\ndown at the bowling alley\nwith fred\nlast night.\n";
#if ($var_sub =~ /Barney.*fred/s){
if ($var =~ /Barney.*fred/s){
print "That matching mentions fred Barney.";
}
#end
3) 用/x加入空白
在模式里随意加入空白,使它阅读更容易:
/-? \d+\.?\d*/
/ -? \ d+ \ .? \ d* /
加入空白后更易于阅读。
附加:
. Match any character
\w Match "word" character (alphanumeric plus "_")
\W Match non-word character
\s Match whitespace character
\S Match non-whitespace character
\d Match digit character
\D Match non-digit character
\t Match tab
\n Match newline
\r Match return
\f Match formfeed
\a Match alarm (bell, beep, etc)
\e Match escape
\021 Match octal char ( in this case 21 octal)
\xf0 Match hex char ( in this case f0 hexidecimal)
You can follow any character, wildcard, or series of characters and/or wildcard with a repetiton. Here's where you start getting some power:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times