[英]Regex ignore character with prefix
I have this js function:我有这个js函数:
value.replace(/[\\\\\\*\\+\\^\\?\\$\\[\\]\\{\\}\\-]/g, '\\\\$&');
which replace:其中替换:
* , + , ^ , ? , & , { , }
with:和:
\\* , \\+ , \\^ , \\? , \\& , \\{ , \\}
but when i have .+
i need it to not be replaced with .\\+
但是当我有
.+
我需要它不被替换为.\\+
what do i need to change in my regex?我需要在我的正则表达式中改变什么?
我认为您可以简单地从正则表达式中删除\\+
,使其形成: value.replace(/[\\\\\\*\\^\\?\\$\\[\\]\\{\\}\\-]/g, '\\\\$&');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.