如何编写正则匹配的test函数进行测试?
- 内容介绍
- 文章标签
- 相关推荐
本文共计477个文字,预计阅读时间需要2分钟。
javascriptvar fnTest=/xyz/.test(function() { xyz; });var superb=/./.test(/./);
// 对于其中的正则表达式匹配函数test的用法,我非常好奇:// /xyz/.test(function() { xyz; }) 我查阅了Mozilla developer center中关于test函数的描述:// Executes (执行)
var fnTest = /xyz/.test(function(){xyz;}) ? /b_superb/ : /.*/;对于其中正则表达式匹配函数test的用法,我很是迷惑:/xyz/.test(function(){xyz;})我查阅了Mozilla developer center中关于test函数的描述:
Executes the search for a match between a regular expression and a specified string. Returns true or false.
字符串中是否有匹配正则表达式的子字符串。返回true或false。
其语法格式:
regexp.test([str])注意这里的参数是字符串,根本没有提到test函数的参数可以是函数的说法。
本文共计477个文字,预计阅读时间需要2分钟。
javascriptvar fnTest=/xyz/.test(function() { xyz; });var superb=/./.test(/./);
// 对于其中的正则表达式匹配函数test的用法,我非常好奇:// /xyz/.test(function() { xyz; }) 我查阅了Mozilla developer center中关于test函数的描述:// Executes (执行)
var fnTest = /xyz/.test(function(){xyz;}) ? /b_superb/ : /.*/;对于其中正则表达式匹配函数test的用法,我很是迷惑:/xyz/.test(function(){xyz;})我查阅了Mozilla developer center中关于test函数的描述:
Executes the search for a match between a regular expression and a specified string. Returns true or false.
字符串中是否有匹配正则表达式的子字符串。返回true或false。
其语法格式:
regexp.test([str])注意这里的参数是字符串,根本没有提到test函数的参数可以是函数的说法。

