Methods for regular Expression objects:
Test a string used to test for the existence of a matching regular expression pattern in a string parameter, if there is a return true , there is no return false .
exec performs a search on a string using the regular expression pattern and updates the global RegExp object to reflect the matching result.
Returns null if there is no matching text , otherwise returns an array of results:
Index declares the position of the first character of the matched text.
input storing the retrieved string string .
Non-global expression for exec:
Returns an array when the Exec () of a non-global RegExp object is called.
The first element is the text that matches the regular expression
The second element is the text (if any) that matches the first subexpression of the Regexpobject.
The third element is the text that matches the second sub-expression of the RegExp object, if any, and so on
Object properties:
Global: Whether full-text search, default false
Ignore case: Whether casing sensitive, default is False
Multiline: Multi-line search, default value is False
LastIndex: Is the next position of the last character of the current expression matching content
Source: literal string of regular expression
Methods for string objects:
The search () method is used to retrieve the substring specified in the string, or to retrieve the substring method that matches the regular expression to return the first matching result index, which is not found to return 1
The search () method does not perform a global match, it ignores the flag G and always retrieves from the beginning of the string
The match () method retrieves a string to find one or more text that matches the RegExp
Whether the regexp has a flag G has a great effect on the results
Non-global invocation of regexp:
If the regexp does not have a flag G, then the match () method can only perform a match in the string
If no matching text is found, NULL is returned
Otherwise it will return an array containing information about the matching text it finds
The first element of the returned array holds the matching text, while the rest of the elements hold the text that matches the subexpression of the regular expression
In addition to the regular array elements, the returned array also contains 2 object properties:
The index declaration matches the starting character of the text in the position of the string
Input declares a reference to Stringobject
Global Invocation of RegExp:
If RegExp has the flag G, the match () method performs a global retrieval to find all matching substrings in the string
No matching substrings were found, then NULL is returned
If one or more matching substrings are found, an array is returned
The array element holds all the matching substrings in the string, and there is no index attribute or input property
Split divide the string into character arrays, and in some complex cases you can use regular expressions to solve
Meaning of the function parameter:
The function is called every time the match is replaced, with four parameters:
Match string
Regular expression grouping content, no grouping without this parameter
The index of the match in the string
Original string
Use of Replace:
String.prototype.replace (STR,REPLACESTR)
String.prototype.replace (REG,REPLACESTR)
String.prototype.replace (reg,function)
JavaScript Regular Expression Three