使用正则表达式 javascript 进行体验 [英] Experiementing with regex javascript
本文介绍了使用正则表达式 javascript 进行体验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定字符串:"hello \\n world"
我将如何使用替换然后将其转换为:"hello \\\n world"
Given the string: "hello \\n world"
how would I use replace to then transform that into: "hello \\\n world"
会是.replace(/\\/g,/\\\\\\/)
吗?
请记住,我知道这是无效的.但我想看看这是否可以做到.我是正则表达式的新手.
Keep in mind I know this is not valid. But I wanted to see if this could be done. And I am new to regex.
推荐答案
试试这个:
var a = "hello \\n world";
var b = a.replace(/\\/g, "\\\\\\");
alert(b);
这篇关于使用正则表达式 javascript 进行体验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文