2014-01-29 66 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,等等......白色空间会被扔掉吗? –

相关问题