Two methods of using regular in JavaScript


In JavaScript, there are two ways to use regular expressions. One is to create an instance of regular expression, but to use the methods related to regular expression in string objects
Regular expression object
Two creation methods
var my_regex=/[a-z]+/g; 
var my_regex=new (“[a-z]+”,”g”);
Exec (string) performs regular processing on strings and returns matching results  
Test (string) to test whether the string contains matching results
Regular in string objects
Match (pattern) performs regular matching according to the pattern. If it matches, it returns the matching result. If it does not match, it returns null
Search (pattern) performs regular matching according to the pattern. If a result is matched, it returns its index number; Otherwise – 1 is returned
Replace (pattern, replacement) performs regular matching according to the pattern and replaces the matching result with replacement
Split (pattern) performs regular segmentation according to the pattern and returns a divided array

Recommended Today

6、 Transaction index view cursor

1、 Business Personnel information is as follows: (the second column is the ID number, and the third column is the bank card number) –Liu Bei 420107198905064135 6225125478544587–Guan Yu 420107199507104133 6225547858741263–Zhang Fei 420107199602034138 6225547854125656 (1) Assuming Liu Bei withdraws 6000 (add check constraint, set account balance must be > = 0), it is required to use […]