2014-10-02 75 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