The RegExp object represents a regular expression, which is a powerful tool for performing pattern matching on strings
var re=/e/; var re=New RegExp (' e ');
Method of the String object of the regular expression
1.search---Retrieves the value that matches the regular expression (returns the subscript)
var a= ' a1a34b4cd5ef5g '; alert (A.search (' a ')); Results: 0alert (a.search (/\d{2}b/g)); Results: 3
2.match---found a match for one or more regular expressions (returns an array)
var a= ' a1a34b4cd5ef5g '; alert (A.search (' a ')); Results: Aalert (A.search (/a/g)); Results: A,a
3.replace (A, b)---Replace substrings that match regular expressions (returns new replaced strings)
A: Required. A RegExp object that specifies a substring or pattern to replace
B: Required. A string value. A function that prescribes replacement text or generates alternate text
var a= ' a1a34b4cd5ef5g '; alert (A.replace (' A ', ' B ')); Results: B1a34b4cd5ef5galert (A.replace (/a/g, ' B ')); Results: b1b34b4cd5ef5g
4.split (A, b)---Split a string into a string array (returns the segmented array)
A: Required. A string or regular expression that is split from the location specified by the parameter
B: Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string will be split, regardless of its length
Test---Detects if a string matches a pattern, matches returns true, otherwise returns false
JavaScript Learning Notes collation (Regular)