Regular expressions are incredibly useful.
They're also remarkably good at making experienced developers stare at 30 characters for five minutes.
Take something simple:
^[A-Za-z0-9]+$
Once you know the pieces, it isn't nearly as intimidating.
'^' means the beginning of the string.
[A-Za-z0-9] matches letters and numbers.
- means one or more.
$ marks the end of the string.
The problem with regex isn't necessarily writing it.
It's remembering all the tiny pieces.
The regex syntax I keep forgetting
Some of the most useful patterns are also the easiest to forget:
\d digit
\w word character
\s whitespace
. any character
+ one or more
* zero or more
? zero or one
^ start
$ end
Then there are groups, character classes, quantifiers, lookaheads and all the other things that send you searching the web again.
So I made myself a reference
While building Sadevz Tools, I created a Regex Cheat Sheet that keeps the common syntax and patterns together in one place.
You can bookmark it here:
I also built a Regex Tester for actually experimenting with patterns:
The combination has become the workflow I prefer:
Reference → write pattern → test → adjust.
No account or installation needed.
Regex probably won't ever become beautiful.
But at least we can make it slightly less hostile. 😄
Top comments (0)