2014-01-29 140 views
0

我想用換行符替換文本行中的每個第六個逗號。我試圖用\ n在文本板中替換{6},但沒有運氣。有任何想法嗎?正則表達式用換行符替換第六個逗號

+0

僅供參考,正則表達式你試圖匹配6個逗號連勝。 – Vache

+0

在構建正則表達式時,請嘗試使用[此工具](http://rick.measham.id.au/paste/explain.pl)來測試它們。 – csmckelvey

+0

感謝大家的回覆。 h2oooooo,你在用什麼程序?我認爲這對Textpad有點過分了。 –

回答

2

/^(([^\n,]+,){5}[^\n,]+),\s*/gm與替換\1\n應該工作正常,取決於你的味道。

/^((.*?,){5}.*?),\s*/gm也可以正常工作,但是您不能擁有DOTALL修飾符。

輸入:

this, is, my, string, and, it, is, very, nice, and, pretty, cool 
this, is, my, string, and, it, is, very, nice, and, pretty, cool 
this, is, my, string, and, it, is, very, nice, and, pretty, cool 
this, is, my, string, and, it, is, very, nice, and, pretty, cool 
this, is, my, string, and, it, is, very, nice, and, pretty, cool¨ 

輸出:

this, is, my, string, and, it 
is, very, nice, and, pretty, cool 
this, is, my, string, and, it 
is, very, nice, and, pretty, cool 
this, is, my, string, and, it 
is, very, nice, and, pretty, cool 
this, is, my, string, and, it 
is, very, nice, and, pretty, cool 
this, is, my, string, and, it 
is, very, nice, and, pretty, cool 

DEMO

+0

什麼程序正在使用?這似乎沒有在文本板中工作。文本排列方式如下:G1/1,G1/2,G1/3,等等......白色空間會被扔掉嗎? –

相關問題