DEV Community

Cover image for The Regex Cheat Sheet for JavaScript Developers

The Regex Cheat Sheet for JavaScript Developers

Sohanur Rahman Emon on December 07, 2023

Regex (Regular Expressions) are powerful tools for pattern matching and text manipulation. They provide a concise and flexible way to describe comp...
Collapse
 
tracygjg profile image
Tracy Gilmore

Hi Sohanur, Three rules I try to apply when using Regular Expressions.
1) Top and tail with ^ and $ whenever possible.
2) Try to limit repetition by replacing + with {1,n} and * with {0,n}, where a reasonable value for n can be determined.
3) Test, test and test some more.

Test all the positive case, as many negative cases as you can devise and test all possible edge cases.