| KW.pm | Regular Expressions | #14 |
print "Found it!\n" if( $haystack =~ m/needle/ );
Returns complete string if there's a match, or captured substrings if parenthesis were used.
e.g. To capture key=value pairs into a hash:
%hash = ( $string =~ /(\w+)=(\w+)/g );
| Modifier | Meaning |
|---|---|
| /g | Globally find all matches |
| /cg | Allow continued search after a failed /g match |
while( m/\b([A-Z][a-z]*)\b/g ) {
print "Found capitalized word $1\n";
}
| << Previous | Index | Next >> | Copyright © 2002 Christopher Calzonetti |