DEV Community

Discussion on: My Regex Cheatsheet - 25 Example Regex Rules

Collapse
 
millebi profile image
Bill Miller

41: \d+ = 1 or more, not 0 or more (that would be * not +)
42: \D+ could be clearer as "1 or more non-digit characters"

Hint: When dealing with more complex RegEx in code; document each piece after it works in a comment in your code. It can be very helpful in the future when you've forgotten how/why it works, and as a reminder of cheats you've found in the past.

Also, beware different languages use slightly different optimizations/interpretations, so a wonderful RegEx in JS may do nothing useful in C++/Perl/C#/Java/Ruby/...