$url='www.*.com/*/100.html*'
有什么简单的办法把100提取并且赋给$id
*里面肯定不会有.html
100只是个例子,可能是其他数字
有什么简单的办法把100提取并且赋给$id
*里面肯定不会有.html
100只是个例子,可能是其他数字
1
123123 Jul 30, 2013
preg_match('~(\d+).html~', $url, $match);
去看看正则三十分钟 |
2
123123 Jul 30, 2013
更正上面正则中的「.」应该是「\.」,虽然结果没什么差
|
4
BeijingBaby Jul 30, 2013
'|/(\d+)\.html|'
|
5
turing Jul 30, 2013 lz 搞不清正则不放用语义化的正则包装:https://github.com/jehna/VerbalExpressions
|
6
lazygunner Jul 31, 2013
import re
p = re.compile(r'^http://www\..*\.com/.*/(?P<num>\d*)\.html$') r = p.search('www.v2ex.com/t/123/html') r.group('num') |