我使用正则表达式将换行符替换为word吗?尝试此正则表达式代码,但不起作用,(.*+)/g
这是我的正则表达式https://regex101.com/r/bW1gN3/2
输入:
one
two
three
four
five
输出:
one
one
two
two
two
two
three
three
three
four
four
four
four
five
GREP本身不能执行此操作,但是由于您使用的不是纯GREP而是一种实际的编程语言,因此可以使用replace
:
str = "one\n\ntwo\n\n\n\nthree\n\n\nfour\n\n\nfive";
str = str.replace (/(.+)\n+/g, function (a,b) { return a.replace(/.*\n/g, b+'\n'); } );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句