String search: from simple to regexp JavaScript) Basic search methods for string objects string". indexof(rin") →2 string". indexof(new RegExp(rn))>-1 等效-" tring" search(new RegExp)4n -string" search(new RegExp(r n)2 string search(r. n/ 2 -"string". match(/tri str/ →["str" string". match(/ri ["st","ri"] string". match(/trilstr/g) strstr 参见( js. htm)
String search: from simple to regexp (JavaScript) • Basic search methods, for String objects: – "string".indexOf("rin") → 2 – "string".indexOf(new RegExp("r*n")) → -1 – "string".search(new RegExp("r*n")) → 4 – "string".search(new RegExp("r.*n")) → 2 – "string".search(/r.*n/) → 2 – "string".match(/tri|str/) → ["str"] – "string".match(/ri|st/g) → ["st", "ri"] – "string".match(/tri|str/g) → ["str"] 参见(js.htm) 6 等效
String search: from simple to regexp JavaScript indexof Syntax: object indexof(search Value, fromIndex) When called from a String object, this method returns the index of the first occurance of the specified searchvalue argument, starting from the specified fromIndex argument. search Syntax: object search(regexp) This method is used to search for a match between a regular expression and the specified string RegExp Syntax new RegExp( "pattern"L flags"l)EfEmyReg=pattern/flags
String search: from simple to regexp (JavaScript) • indexOf – Syntax: object.indexOf(searchValue,[fromIndex]) – When called from a String object, this method returns the index of the first occurance of the specified searchValue argument, starting from the specified fromIndex argument. • search – Syntax: object.search(regexp) – This method is used to search for a match between a regular expression and the specified string. – RegExp – Syntax: • new RegExp(“pattern”[, “flags”])或者myReg=pattern/flags
String search: from simple to regexp JavaScript match Syntax: object. match(regexp) This method is used to match a specified regular expression against a string If one or more matches are made, an array is returned that contains all of the matches. Each entry in the array is a copy of a string that contains a match. if no match is made, a nullis returned To perform a global match you must include the g global flag in the regular expression and to perform a case-insensitive match you must include the i'(ignore case) flag ·匹配用过的不用用于匹配
String search: from simple to regexp (JavaScript) • match – Syntax: object.match(regexp) – This method is used to match a specified regular expression against a string – If one or more matches are made, an array is returned that contains all of the matches. Each entry in the array is a copy of a string that contains a match. If no match is made, a null is returned. To perform a global match you must include the 'g' (global) flag in the regular expression and to perform a case-insensitive match you must include the 'i' (ignore case) flag. • 匹配用过的串不再用于匹配