首页 > 其他分享 >无涯教程-RegExp.prototype.test()函数

无涯教程-RegExp.prototype.test()函数

时间:2024-02-07 18:31:59浏览次数:28  
标签:returned 无涯 Test result test RegExp prototype

test()方法在字符串中搜索与正则表达式匹配的文本。如果找到匹配项,则返回true;否则,它返回false。

RegExp.prototype.test() - 语法

RegExpObject.test( string );          
  • string    -  要搜索的字符串。

RegExp.prototype.test() - 返回值

如果找到匹配项,则返回匹配的文本,否则返回NULL。

RegExp.prototype.test() - 示例

var str="Javascript is an interesting scripting language"; 
var re=new RegExp( "script", "g" ); 
var result=re.test(str); 
console.log("Test 1 - returned value : " +  result);  
re=new RegExp( "pushing", "g" ); 
var result=re.test(str); 
console.log("Test 2 - returned value : " +  result); 

运行上面代码输出

Test 1 - returned value : true 
Test 2 - returned value : false     

参考链接

https://www.learnfk.com/es6/es6-regexp-prototype-test.html

标签:returned,无涯,Test,result,test,RegExp,prototype
From: https://blog.51cto.com/u_14033984/9639525

相关文章

  • 无涯教程-RegExp.prototype.exec()函数
    exec方法在字符串中搜索与正则表达式匹配的文本。如果找到匹配项,则返回输出数组。否则,返回null。RegExp.prototype.exec()-语法RegExpObject.exec(string);string  - 要搜索的字符串RegExp.prototype.exec()-返回值如果找到匹配项,则返回匹配的文本,否则......
  • 无涯教程-RegExp.prototype.sticky函数
    lastIndexRegExp对象的读/写属性。对于设置了"g"属性的正则表达式,它包含一个整数,该整数指定紧随RegExp.exec()和RegExp.test()方法找到的最后一个匹配项之后的字符位置,这些方法使用此属性作为它们进行下一次搜索的起点。RegExp.prototype.sticky-语法RegExpObject.lastInde......
  • 无涯教程-RegExp.prototype.multiline函数
    multiline是RegExp对象的只读布尔属性。它指定特定的正则表达式是否执行多行匹配,即是否使用"m"属性创建。RegExp.prototype.multiline-语法RegExpObject.multilineRegExp.prototype.multiline-返回值如果设置了"m"修饰符,则返回"TRUE",否则返回"FALSE"。RegE......
  • 无涯教程-RegExp.prototype.ignoreCase函数
    ignoreCase是RegExp对象的只读布尔属性。它指定特定的正则表达式是否执行不区分大小写的匹配,即是否使用"i"属性创建。RegExp.prototype.ignoreCase-语法RegExpObject.ignoreCaseRegExp.prototype.ignoreCase-返回值如果设置了"i"修饰符,则返回"TRUE",否则返回"......
  • 无涯教程-RegExp.prototype.global函数
    global是RegExp对象的只读布尔属性。它指定特定的正则表达式是否执行全局匹配,即是否使用"g"属性创建。RegExp.prototype.global-语法RegExpObject.globalRegExp.prototype.global-返回值如果设置了"g"修饰符,则返回"TRUE",否则返回"FALSE"。RegExp.prototype.......
  • 无涯教程-Math.atan2(y, x0)函数
    atan2方法介于-PI/2与PI/2弧度之间的数值来返回x的反正切值。Math.atan2-语法Math.atan2(x,y)x和y  - 代表一个数字Math.atan2-示例console.log("---Math.atan2()---")console.log("Math.atan2(0):"+Math.atan2(0,1))console.log("Math.atan2(M......
  • 无涯教程-Math.acos(x)函数
    此函数返回x的反余弦值。Math.acos(x)-语法Math.acos(x)x  - 代表数字Math.acos(x)-示例console.log("---Math.acos()---")console.log("Math.acos(0):"+Math.acos(0))console.log("Math.acos(Math.SQRT1_2):"+Math.acos(Math.SQRT1_2))......
  • 无涯教程-Math.asin(x)函数
    此函数返回x的反正弦。Math.asin(x)-语法Math.asin(x)x  - 代表数字Math.asin(x)-示例console.log("---Math.asin()---")console.log("Math.asin(0):"+Math.asin(0))console.log("Math.asin(Math.SQRT1_2):"+Math.asin(Math.SQRT1_2))......
  • 无涯教程-Math.max((x1, x2,...)函数
    此方法返回零或多个数字中的最大值。如果未提供任何参数,则输出为–Infinity。Math.max-语法Math.max(x1,x2,x3..)X1,x2,x3..  - 代表一系列数字Math.max-示例console.log("---Math.max()---")console.log("Math.max(3,0.5,0.66):"+Math.max(3,0.5,......
  • 无涯教程-Math.round(x)函数
    将数字四舍五入到最接近的整数。Math.round(x)-语法Math.round(x);x  - 代表数字Math.round(x)-示例console.log("---Math.round()---")console.log("Math.round(7.2):"+Math.round(7.2))console.log("Math.round(-7.7):"+Math.round(-7.......