python正则表达式的字符串捕获问题
<input name="salt" type="hidden" value="1350911390734">
这样一段字符串串中,我需要这个值:1350911390734
在perl里面可以用括号进行捕获,但是python我没怎么接触过,不熟悉,用正则的话要怎么搞?
[解决办法]
- C/C++ code
[root@vps616 python]# python main.py1350911390734[root@vps616 python]# cat main.py#python2.7.3#coding=utf-8import recontent = '"<input name="salt" type="hidden" value="1350911390734">"'match = re.search(r'<input name="salt" type="hidden" value="(\d+)">', content)if match: print match.group(1)
[解决办法]
- Python code
C:\Users\ago>pythonPython 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import re>>> string = '<input name="salt" type="hidden" value="1350911390734">'>>> re.findall('[0-9]{13}',string)[0]'1350911390734'>>>