2011-07-01 50 views
-1

此之間提取數據是一個測試字符串 「透明URL(http://www.google.com/chart?chs=630x100 & CHT = BVS & chxt = X & chxl = 0:%7C1840%7C1860%7C1880%7C1900%7C1920%7C1940%7C1960%7C1980%7C2000%7C &反饋網站0,0,100 & chxs = 0,676767,11.3000002,0,TL,676767,676767 & CHD = E:D9AACPFjGWAAGDLfCeFgBvHLLSCZGED5GOKwDKCxJmF2FwFfERFwEZGcEJHlENJDJ9I0HQDjE -MAK2J9NMI9IAFtNaIOKtGoG2IYKBFvLEJmMLHdIFHXG.IPHrK2I9ULROI8SfHRFTeCIrQPOwXgPHVxQkbCbhg8iDwIvKkety..AAAAAAAA & chbh = 7,0,0 & CHG = 11.11,0,5,6 & chxp = 0,0.0,11.1,22.2,33.3,44.4,55.6,66.7,77.8,88.9 & CH共= 3366CC,bbcced & CHM = R,BBBBBB,0,0.9954,1.0%7CH,BBBBBB,0,1.0,1.0,1 & chxs = 0,000000,11,-1 & HL =烯)」使用Python中re模塊到兩個支架

我想提取兩個括號之間的所有數據 - 第一行中的url後面的一個和最後的右括號 - 使用Python的重新模塊

+0

我試過這個re.search(「url \ \(。\\)「,字符串)以及其他變體 –

+0

您接近然後're.search(r'\((。*)\)',string).group(1)' –

回答

1
[email protected]:/tmp$ python 
Python 2.6.7 (r267:88850, Jun 13 2011, 22:03:32) 
[GCC 4.6.1 20110608 (prerelease)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import re 
>>> re.compile('\(([^)]*)\)').search("transparent url(http://www.google.com/chart?chs=630x100&cht=bvs&chxt=x&chxl=0:%7C1840%7C1860%7C1880%7C1900%7C1920%7C1940%7C1960%7C1980%7C2000%7C&chxr=0,0,100&chxs=0,676767,11.3000002,0,tl,676767,676767&chd=e:D9AACPFjGWAAGDLfCeFgBvHLLSCZGED5GOKwDKCxJmF2FwFfERFwEZGcEJHlENJDJ9I0HQDjE-MAK2J9NMI9IAFtNaIOKtGoG2IYKBFvLEJmMLHdIFHXG.IPHrK2I9ULROI8SfHRFTeCIrQPOwXgPHVxQkbCbhg8iDwIvKkety..AAAAAAAA&chbh=7,0,0&chg=11.11,0,5,6&chxp=0,0.0,11.1,22.2,33.3,44.4,55.6,66.7,77.8,88.9&chco=3366cc,bbcced&chm=R,bbbbbb,0,0.9954,1.0%7Ch,bbbbbb,0,1.0,1.0,1&chxs=0,000000,11,-1&hl=en)").groups()[0] 
'http://www.google.com/chart?chs=630x100&cht=bvs&chxt=x&chxl=0:%7C1840%7C1860%7C1880%7C1900%7C1920%7C1940%7C1960%7C1980%7C2000%7C&chxr=0,0,100&chxs=0,676767,11.3000002,0,tl,676767,676767&chd=e:D9AACPFjGWAAGDLfCeFgBvHLLSCZGED5GOKwDKCxJmF2FwFfERFwEZGcEJHlENJDJ9I0HQDjE-MAK2J9NMI9IAFtNaIOKtGoG2IYKBFvLEJmMLHdIFHXG.IPHrK2I9ULROI8SfHRFTeCIrQPOwXgPHVxQkbCbhg8iDwIvKkety..AAAAAAAA&chbh=7,0,0&chg=11.11,0,5,6&chxp=0,0.0,11.1,22.2,33.3,44.4,55.6,66.7,77.8,88.9&chco=3366cc,bbcced&chm=R,bbbbbb,0,0.9954,1.0%7Ch,bbbbbb,0,1.0,1.0,1&chxs=0,000000,11,-1&hl=en' 
相關問題