1. Match 11 mobile phone numbers with the first letter of 1
^1\d{10}$
2. Matching name, 3-6 characters in Chinese
[\u4e00-\u9fa5]{3,6}
3. Matching password must be 6-16 characters, and can only contain numbers, letters and underscores:
$\w{6-16}^
4. Matching mailbox
^\w+@\w+(\.\w+){1,2}
5. Match the number of the seat
^\d{1,3}-\d{4,8}$
6. Match a positive number
^\d+(\.\d+)?$
7. Match a decimal
^-?\d+\.\d+
8. Match an integer
^-?\d+$
9. Write a regular expression to match a string to get the number of matches and the results
index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> var reg = /\d{3}/g; var s = "1234a;sdfja;sd234lkfjasldkfj"; var n = 0; while(result = reg.exec(s)){ n++; console.log(result[0]); } console.log(`matching ${n}second`); </script> </body> </html>