Eight regular expressions you should know to improve your productivity

Time:2020-10-23

Regular expressions can also be considered a language, and when you learn a new programming language, they are a small sublanguage. It doesn’t make any sense at first, but most of the time, you have to read some tutorials or articles to understand these simple description patterns. Here are eight basic regular expressions

1. Match user name: / ^ [a-z0-9_ -]{3,16}$/  
2. Matching password: / ^ [a-z0-9_ -]{6,18}$/   
3. Match a hex value: / ^? ([a-f0-9] {6}| [a-f0-9] {3}) $/ 
4. Match a slug: / ^ [a-z0-9 -] + $/ 
5. Match an email: / ^ ([a-z0-9_ \.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/   
6. Match a URL: / ^ (HTTPS?: \ / \ /)? ([\ da-z \. -] +) \. ([A-Z \.] {2,6}) ([\ / \ w \. -] * * \ /? $/ 
7. Matching IP address: / ^ (?: 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?) \) {3} (?: 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?) $/ 
8. Matching HTML tag: 1. / ^ < ([A-Z] +) ([^ <] +) * (?: > (. *) < \ / \ \ 1 > | S + \ / >) $/