正则表达式用换行符替换第6个逗号

时间:2014-01-29 21:44:16

标签: regex

我正在尝试用换行符替换文本行中的每个第6个逗号。我试过用文本板中的\ n替换{6}而没有运气。有任何想法吗?

1 个答案:

答案 0 :(得分: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

相关问题