本文介绍了允许“/”正则表达式中的正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var patt = / ^(?=。* [a-zA-Z0-9。!@#& * \-\ u0080-\ u052F])[ !A-ZA-Z0-9\s @#&放大器; *,\-\\\€-\\\ԯ] * $ /; 
console.log(patt.test(\ u002f));

我知道u002f是Unicode中的正斜杠。我已经尝试将其添加到模式以及/并且还无法使其记录为真。

解决方案

很容易添加正斜杠,只是逃避它。不需要使用任何字符引用或实体。

  var patt = /^(?=.*[a-zA-Z0- !9 @#&安培;!* \-\\\€-\\\ԯ])[\ / A-ZA-Z0-9\s @#&安培; *,\-\\\€- \\\ԯ] * $ /; 
^

  var patt = /^(?=.* [!一个-ZA-Z0-9 @#&安培; * \-\\\€-\\\ԯ]!)[\ / A-ZA-Z0-9\s @#&安培; *, \-\\\€-\\\ԯ] * $ /;警报(patt.test( /测试));  


var patt = /^(?=.*[a-zA-Z0-9.!@#&*\-\u0080-\u052F])[a-zA-Z0-9\s.!@#&*',\-\u0080-\u052F]*$/;
console.log(patt.test("\u002f"));

I know that u002f is a forward slash in Unicode. I've tried adding that to the pattern as well as "/" and haven't been able to get it to log true yet.

解决方案

It is easy to add a forward slash, just escape it. No need using any character references or entities.

var patt = /^(?=.*[a-zA-Z0-9.!@#&*\-\u0080-\u052F])[\/a-zA-Z0-9\s.!@#&*',\-\u0080-\u052F]*$/;
                                                    ^                 

var patt = /^(?=.*[a-zA-Z0-9.!@#&*\-\u0080-\u052F])[\/a-zA-Z0-9\s.!@#&*',\-\u0080-\u052F]*$/;
alert(patt.test("/test"));

这篇关于允许“/”正则表达式中的正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:23