目录

RegExp.prototype.search()

此方法返回在字符串中找到匹配项的索引。 如果未找到匹配项,则返回-1。

语法 (Syntax)

str.replace(regexp|substr, newSubStr|function)           

参数的细节 (Parameter Details)

  • Regexp - 正则表达式对象。

  • Substr - 要替换​​的字符串。

  • newSubStr - 替换字符串。

  • function - 创建新字符串的函数。

返回值 (Return Value)

返回在字符串中找到匹配项的索引。

例子 (Example)

var str = 'Welcome to ES6.We are learning ES6'; 
var re = new RegExp(/We/); 
var found = str.search(re); 
console.log(found); 

输出 (Output)

0     
↑回到顶部↑
WIKI教程 @2018