返回正则表达式搜索中第一个子字符串匹配项的位置。
function search(rgExp : RegExp) : Number
- rgExp
必选。包含正则表达式模式和适用标志的 Regular Expression 对象的实例。
search 方法表示是否找到了匹配项。如果找到一个匹配项,则 search 方法将返回一个整数值,该值指示发生匹配处距字符串开头的偏移量。如果没有找到匹配项,则返回 -1。
示例下面的示例阐释了 search 方法的用法。
function SearchDemo(){ var r, re; //Declare variables. var s = "The rain in Spain falls mainly in the plain."; re = /falls/i; //Create regular expression pattern. r = s.search(re); //Search the string. return(r); //Return the index to the first match //or –1 if no match is found. }要求
应用于:
参考
exec 方法match 方法
正则表达式对象
replace 方法
test 方法