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

无涯教程-RegExp.prototype.sticky函数

时间:2024-02-07 16:31:55浏览次数:24  
标签:Index 无涯 sticky Current re RegExp prototype

lastIndex RegExp对象的读/写属性。对于设置了" g"属性的正则表达式,它包含一个整数,该整数指定紧随RegExp.exec()和RegExp.test()方法找到的最后一个匹配项之后的字符位置,这些方法使用此属性作为它们进行下一次搜索的起点。

RegExp.prototype.sticky - 语法

RegExpObject.lastIndex          

RegExp.prototype.sticky - 返回值

返回一个整数,该整数指定最后匹配之后的字符位置。

RegExp.prototype.sticky - 示例

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

运行上面代码输出

Test 1 - Current Index: 10 
Test 2 - Current Index: 35       

参考链接

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

标签:Index,无涯,sticky,Current,re,RegExp,prototype
From: https://blog.51cto.com/u_14033984/9638858

相关文章

  • 无涯教程-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.......
  • 无涯教程-Math.floor(x)函数
    floor()方法对x进行下舍入。Math.floor(x)-语法Math.floor(x);x  - 代表数字Math.floor(x)-示例console.log("---Math.floor()---")console.log("Math.floor(2.8):"+Math.floor(2.8))console.log("Math.floor(-3.2):"+Math.floor......
  • 无涯教程-Math.ceil(x)函数
    ceil()方法对数进行上舍入。Math.ceil(x)-语法Math.ceil(x);x  - 代表数字Math.ceil(x)-示例console.log("---Math.ceil()---")console.log("Math.ceil(2.2):"+Math.ceil(2.2))console.log("Math.ceil(-3.8):"+Math.ceil(-3.8))......