http://www.perlhowto.com/match_the_shortest_possible_string
The pattern matching quantifiers of a Perl regular expression are "greedy" (they match the longest possible string). To force the match to be "ungreedy", append a ? to the pattern quantifier (*, +).
Example:
#!/usr/bin/perl
$string="111s11111s";
#-- greedy match
$string =~ /^(.*)s/;
print "$1\n"; # prints 111s11111
#-- ungreedy match
$string =~ /^(.*?)s/;
print "$1\n"; # prints 111
'Programming' 카테고리의 다른 글
regular expression (0) | 2013.10.04 |
---|---|
(Perl) Passing a Function Object and Calling it (0) | 2013.10.01 |
perlintro (0) | 2013.09.16 |
(JavaScript) refresh or close??? (0) | 2013.09.12 |
Creating multiline strings in JavaScript (0) | 2013.09.08 |