admin管理员组文章数量:1424409
I want to insert newline character in regex replace what field.
For example:
Find With: (xyxyxy.*[\r\n]+)(yzyzyz)
Replace with: $1xyxyxy\r\nxyxyxy
also tried replace with: $1xyxyxy$r$nxyxyxy
None of them seems to be working.
Question is what is the mantra to insert carriage return and/or new line via regex replace.
I want to insert newline character in regex replace what field.
For example:
Find With: (xyxyxy.*[\r\n]+)(yzyzyz)
Replace with: $1xyxyxy\r\nxyxyxy
also tried replace with: $1xyxyxy$r$nxyxyxy
None of them seems to be working.
Question is what is the mantra to insert carriage return and/or new line via regex replace.
Share Improve this question edited Feb 17, 2016 at 9:30 Rahul asked Feb 17, 2016 at 9:28 RahulRahul 11.6k5 gold badges61 silver badges97 bronze badges 9-
Are you sure it is JS? Not VBScript? In VBScript, you need
vbCrLf
:"$1xyxyxy" & vbCrLf & "xyxyxy"
– Wiktor Stribiżew Commented Feb 17, 2016 at 9:29 - Can you please show a sample input and the corresponding desired output? – nnnnnn Commented Feb 17, 2016 at 9:34
- @WiktorStribiżew: I Think That is not good Idea. – Rahul Commented Feb 17, 2016 at 9:35
- @nnnnnn: simple question: what is the regex character to insert newline. In \r\n will insert the newline. How to insert carriage return in the replace what field. – Rahul Commented Feb 17, 2016 at 9:37
-
@Rahul: why not a good idea? There is no regex character to insert newline. Newline sequence can be matched with special shorthand character class, but not in VBScript. Do you mean you do not want to hardcode the newline sequence? Then, try Tushar's approach:
(xxxxxx.*(\r\n|\r|\n)+)
->$1$2$3
. – Wiktor Stribiżew Commented Feb 17, 2016 at 9:40
1 Answer
Reset to default 7You can capture the newline characters and use that in replacement. By capturing the newline characters, you don't have to worry about differences in different OS representation of newline.
Find:
(xyxyxy.*(\r\n|\r|\n)+)(yzyzyz)
Replace:
$1$2$3
$2
: Is the single newline character.
本文标签: javascriptHow to insert carriage return in regex replaceStack Overflow
版权声明:本文标题:javascript - How to insert carriage return in regex replace - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745423885a2658023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论