分页: 1 / 1
在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-29 11:38
由 hellojinjie
代码: 全选
#noticep{ margin:0 10px; width:660px; background:url(http://mobile.qq.com:8080/web_mobile/mobile_res/mobile2009/images/double_line.gif) repeat-x bottom; padding-bottom:20px; }
比如上面这是一行,我要得到图片连接部分。
另外,在sed grep awk 里有环视的吗
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-29 12:44
由 HuntXu
代码: 全选
echo "#noticep{ margin:0 10px; width:660px; background:url(http://mobile.qq.com:8080/web_mobile/mobile_res/mobile2009/images/double_line.gif) repeat-x bottom; padding-bottom:20px; }" |sed -r "s|.+(http://[A-Za-z0-9_./:]+).+|\1|g"
这样子的么?
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-29 20:45
由 hellojinjie
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-29 20:51
由 hellojinjie
sed -r "s|.+(http://[A-Za-z0-9_./:]+).+|\1|g"
HuntXu, 你写的sed我有点不太懂,可以帮我解释下吗。
第一处,| 竖线是什么?书上讲的是/斜线啊,是不是当有 -r 时要用竖线
第二处,\1是什么啊,是指前面匹配的第一的括号内的东西的吗?
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-29 23:52
由 HuntXu
1.竖线和斜线一样,分割符而已...因为链接里有斜线,如果用斜线做分割符会有一堆转义的"\/"...
2.是
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-30 8:57
由 hellojinjie
thx

Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-30 9:23
由 xiooli
这样不是更简单么?
代码: 全选
echo "#noticep{ margin:0 10px; width:660px; background:url(http://mobile.qq.com:8080/web_mobile/mobile_res/mobile2009/images/double_line.gif) repeat-x bottom; padding-bottom:20px;}"|awk -F'[()]' '{print $2}'
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-30 9:32
由 hellojinjie
原来awk的分割符还可以是这样的。
可以是正则表达式的吗,试试
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-31 5:51
由 aerofox
代码: 全选
grep -o "http://[^)]*"
Re: 在shell里怎么得到正则匹配的部分啊
发表于 : 2009-03-31 16:22
由 hellojinjie
aerofox 写了:代码: 全选
grep -o "http://[^)]*"
原来grep还有o这个选项,受教了,thanks