2014-10-02 79 views
0

我必須找到在第二行(位置17)某些供應商根據數查找,分割和級聯

例如,我必須找到,分裂並連接此類型的文本 - (該說明符發現,拆分和連接是第二行 - NUMBER,它由6個數字組成 ,所以我必須找到這個數字並按此數字連接)

我必須使用某種正則表達式嗎?或只發現,拆分和連接? (根據號碼 - 45107,57107)

輸出也在這裏:

Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 

輸出(找到後,分割與串連):

Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
+0

我沒有看到六個數字的任何地方... – isedev 2014-10-02 07:51:39

+0

加入一些預期的輸出可能會讓你的問題更清晰一點 – 2014-10-02 08:06:50

+0

嗨!數字47107和57107,預計產量也在這裏,PLZ的幫助。 – 2014-10-02 08:17:43

回答

0

你似乎想用數字排序的輸出,這樣就可以使用re.split,並用lambda排序,如果爲發佈所有的輸出:

s = """ 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
""" 
import re 

srt = sorted(re.split("(?<=which CPython is used.)\n",s),key=lambda x: re.findall("\d{5}",x)) 

for line in srt: 
    print line 

Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      47107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
Add and Remove Platforms. 
      57107 Specify which Python runtime, CPython or Jython, to use as a 
Choose which CPython is used. 
+0

你如何發現這是OP的問題? – Kasramvd 2014-10-02 08:38:18

+0

@Kasra,*我需要數字(47107和57107 NEXT to each other)*,從輸出看起來非常像一個排序的項目列表,按5位數字排序 – 2014-10-02 08:49:54