In JavaScript, the syntax for the search() method is: string.search(search_expression); Parameters or Arguments search_expression It is either a string value or a RegExp object that will be searched for instring. As a RegExp object, it can be a combination of the following: ...
所有主流浏览器都支持 search 方法。 示例 JavaScript String search() Method var re = /apples/gi; var str = "Apples are round, and apples are juicy."; if ( str.search(re) == -1 ) { document.write("Does not contain Apples" ); } else { document.write("Contains Apples" ); ...
string.search(regexp); HTML 参数详细信息 regexp− 正则表达式对象。如果传递了一个非RegExp对象obj,则使用new RegExp(obj)隐式转换为RegExp。 返回值 如果成功,则搜索返回字符串内正则表达式的索引。否则,返回-1。 例子 尝试以下示例。 JavaScript String search() Methodvarre=/apples/gi;varstr="Apples ...
Javascript examples for String:search HOME Javascript String search Description The search() method searches a string for a specified value or a regular expression, and returns the position of the match. This method returns -1 if no match is found. ...
Thesearch()method returns -1 if no match is found. Thesearch()method is case sensitive. Note ** If the search value is a string, it is converted to a regular expression. See Also: String Search Regular Expression Tutorial Regular Expression Reference ...
JavaScript String search() 方法 search()方法在字符串中搜索指定的值,并返回匹配的位置。搜索值可以是字符串或正则表达式。如果未找到匹配项,则此方法返回-1。 在RegExp教程和RegExp对象参考中阅读有关正则表达式的更多信息。 实例: 搜索“jc2182”: ...
JavaScript string.search() Method string.search() 方法是 JavaScript 中的内置方法,用于在正则表达式和给定字符串对象之间搜索匹配项。 语法: string.search(A) 参数:此方法接受一个参数 A,它将正则表达式作为对象保存。 返回值:此函数返回正则表达式和给定字符串对象之间的第一个匹配字符串的索引,如果没有找到匹配...
JavaScript String search() Method const str = "Welcome to Tutorials Point"; document.write("Original String: ", str); let regexp = /point/i; document.write("regexp: ", regexp); document.write("The sub-string '", regexp, "' found at position ",str.search(regexp)); ...
JavaScript String search() Method: Here, we are going to learn about the search() method of String in JavaScript.
letstr ="GeeksforGeeks";letsearchString ="for";letResult = str.search(searchString);console.log(Result); 输出 5 我们有 Javascript 字符串方法的完整列表,要检查这些方法,请查看Javascript 字符串完整参考文章。 注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品JavaScript String search() Method。