2017-10-31 2 views
-1

が結果である前に改行を挿入する:私は大腸などの前の単語の前にキャリッジを追加する必要が使用正規表現私はここにウェブサイトを掻き取ってきた特定のパターン

Description 
Cap: 4-9 cm Pale brown - often lighter towards the edge. 
Viscid when wet.Gills: Pale clay-brown. Free. Gill edge exude droplets 
when moist which dry to form dark spots.Stem: Off-white. Mealy towards 
the apex.Spores: Clay-brownFlesh: Firm, white. Smell of 
radishesHabitat: In groups or rings on the ground in mixed 
woodlandFrequency: Very Common 

。 \ r \ nGills:情報をより読みやすくするためです。

re.sub()はこれを行う最善の方法ですか?

答えて

0
text_with_rc=re.sub(r'\.\s*',r'.\r\n',the_text) 
0

はいreが必要です。以下のパターンを試してください

str1=re.sub(r'(\w*:)',r'\r\n\1',string) 
>>> print str1 
Description 


Cap: 4-9 cm Pale brown - often lighter towards the edge. 
Viscid when wet. 

Gills: Pale clay-brown. Free. Gill edge exude droplets 
when moist which dry to form dark spots. 

Stem: Off-white. Mealy towards 
the apex. 

Spores: Clay- 

brownFlesh: Firm, white. Smell of 


radishesHabitat: In groups or rings on the ground in mixed 


woodlandFrequency: Very Common 
>>> 
+0

ありがとうございましたSandeepこれがスポットでした。 –

+0

@ 0_o助けてくれてうれしいです。それがあなたの質問に答えるならば、答えとして投稿を更新してください –

関連する問題