2016-11-25 66 views
2

如何編寫re.split()將內容分割爲「.I number」,「。T」,「。A」,「 .B「,」。W「?因爲我想單獨保存內容。如何在某些模式下爲某個字符串編寫re.split()python

.I 1 
    .T 
    experimental investigation of the aerodynamics of a 
    wing in a slipstream . 
    .A 
    brenckman,m. 
    .B 
    j. ae. scs. 25, 1958, 324. 
    .W 
    experimental investigation of the aerodynamics of a 
    wing in a slipstream . 
     an experimental study of a wing in a propeller slipstream was 
    made in order to determine the spanwise distribution of the lift 
    increase due to slipstream at different angles of attack of the wing 
    and at different free stream to slipstream velocity ratios . the 
    results were intended in part as an evaluation basis for different 
    theoretical treatments of this problem . 
     the comparative span loading curves, together with 
    supporting evidence, showed that a substantial part of the lift increment 
    produced by the slipstream was due to a /destalling/ or 
    boundary-layer-control effect . the integrated remaining lift 
    increment, after subtracting this destalling lift, was found to agree 
    well with a potential flow theory . 
     an empirical evaluation of the destalling effects was made for 
    the specific configuration of the experiment . 
    .I 2 
    .T 
    simple shear flow past a flat plate in an incompressible fluid of small 
    viscosity . 
    .A 
    ting-yili 
    .B 
    department of aeronautical engineering, rensselaer polytechnic 
    institute 
    troy, n.y. 
    .W 
    simple shear flow past a flat plate in an incompressible fluid of small 
    viscosity . 
    in the study of high-speed viscous flow past a two-dimensional body it 
    is usually necessary to consider a curved shock wave emitting from the 
    nose or leading edge of the body . consequently, there exists an 
    inviscid rotational flow region between the shock wave and the boundary 
    layer . such a situation arises, for instance, in the study of the 
    hypersonic viscous flow past a flat plate . the situation is somewhat 
    different from prandtl's classical boundary-layer problem . in prandtl's 
    original problem the inviscid free stream outside the boundary layer is 
    irrotational while in a hypersonic boundary-layer problem the inviscid 
    free stream must be considered as rotational . the possible effects of 
    vorticity have been recently discussed by ferri and libby . in the 
    present paper, the simple shear flow past a flat plate in a fluid of small 
    viscosity is investigated . it can be shown that this problem can again 
    be treated by the boundary-layer approximation, the only novel feature 
    being that the free stream has a constant vorticity . the discussion 
    here is restricted to two-dimensional incompressible steady flow . 

如何寫re.split()分割內容轉換成 「.I號碼」, 「T」, 「一種」, 「B」, 「W」 ??因爲我想單獨保存內容。

+0

不回答你的「重」的問題,但你真的應該尋找與一個現成的解析器使用正則表達式這樣做,而不是滾動您自己。 http://pyparsing.wikispaces.com/應該做到這一點。 – roarsneer

+0

're.split(r'(?m)^ \ s +(?= \。[TABW] \ s * $)',s)',參見[本演示](https://regex101.com/r/ 4g0zwK/1)。 –

回答

0

這幾乎是它,除了最後一個,它會得到所有的領域,也許你會弄清楚如何完成它?

請注意,我們需要re.DOTALL,以便.捕獲換行符,並使用.*?以便匹配非貪婪。

re.findall("\.I(.*?)\.T(.*?)\.A(.*?)\.B(.*?)\.W(.*?)", s, re.DOTALL) 
相關問題