py中如何用正则表达式,获取一段字符串。
比如字符串:{"test":"a1b2c3","testtoo":123},我想获取a1b2c3这部分字符串,怎么操作?谢谢。
[解决办法]
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> txt = '{"test":"a1b2c3","testtoo":123}'
>>> import re
>>> r = re.search(r':"(\w+)"', txt)
>>> print r.groups()
('a1b2c3',)
>>>