splitting data using regex in python -


i have file of many line. of format below,

//many lines of normal text        00.0000125  1319280   9.2  shawshank redemption (1994) //lines of text       0000011111      59   6.8  "$#*! dad says" (2010) {you can't handle truce (#1.10)}       1...101002      17   6.6  "$1,000,000 chance of lifetime" (1986) 

i want split data columns 1...101002,17,6.6,"$1,000,000 chance of lifetime" (1986)

the program tried ,

import re f = open("e:/file.list"); reg = re.compile('[+ ].{10,}[+ ][+0-9].{3,}[+ ]') each in f: if reg.match(each):     print each     print reg.split(each) 

it not giving correct answer can know regex use.

it easier match instead of split in case.

^\s*(\s+)\s+(\s+)\s+(\s+)\s+(.*)$ 

try this.see demo.

http://regex101.com/r/oe6jj1/47

import re p = re.compile(ur'^\s*(\s+)\s+(\s+)\s+(\s+)\s+(.*)$', re.ignorecase | re.multiline) test_str = u"00.0000125 1319280 9.2 shawshank redemption (1994)\n\n 0000011111 59 6.8 \"$#*! dad says\" (2010) {you can't handle truce (#1.10)}\n 1...101002 17 6.6 \"$1,000,000 chance of lifetime\" (1986)"  re.findall(p, test_str) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -