Javascript Regex Search

javascript-regex

The [@@search]() method executes a search for a match between a this regular 
expression and a string.

regexp[Symbol.search](str)

If successful, [@@search]() returns the index of the first match of the regular 
expression inside the string. Otherwise, it returns -1.

var re = /-/g;
var str = '2016-01-02';
var result = re[Symbol.search](str);
console.log(result);  // 4
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License