In Javascript, there are two ways to use regular expressions. One is to create an instance of a regular expression, but to use the regular expression related methods in the String object.
Regular Expression object
Two creation methods
Var my_regex =/[a-z] +/g;
Var my_regex = new ("[a-z] +", "g ");
Method
Exec (string), which is used to RegEx the string and returns the matching result.
Test (string) to test whether the string contains matching results
Regular Expressions in string objects
Method
Match (pattern) performs regular match based on pattern. If it matches, the matching result is returned. If it does not match, null is returned.
Search (pattern) performs regular match based on pattern. If a result is matched, the number of indexes is returned; otherwise,-1 is returned.
Replace (pattern, replacement) performs regular matching based on pattern and replaces the matching result with replacement.
Split (pattern) performs regular segmentation based on pattern and returns a split array.