分页: 1 / 1

这个正则表如何理解?

发表于 : 2007-05-05 22:28
hackem
/<img src="(.*?)"/m

===
我想应该是捕获网页的图片
<img src="
这样开始的行,但不明白后面的"(.*?)"/m

发表于 : 2007-05-05 23:45
ziyun
你把表达式写完整看看

发表于 : 2007-05-06 0:08
eexpress
带?结束的。

发表于 : 2007-05-10 23:43
csbde
带?结束的,不然不会有个?

发表于 : 2007-05-11 0:35
5451vs5451

代码: 全选

$ perldoc perlre
......
       By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a partic‐
       ular starting location) while still allowing the rest of the pattern to match.  If you want it to match the mini‐
       mum number of times possible, follow the quantifier with a "?".  Note that the meanings don’t change, just the
       "greediness":

           *?     Match 0 or more times
           +?     Match 1 or more times
           ??     Match 0 or 1 time
           {n}?   Match exactly n times
           {n,}?  Match at least n times
           {n,m}? Match at least n but not more than m times
......
如果这是一个 perl 正则表达式,那么它相当于/<img src="([^"]*)"/m。后面的 m 指多行匹配,也就是允许 '.' 匹配 '\n'。