Welcome to this week’s edition of System Design Weekly! This time, it’s a concise but valuable read — featuring a cheat sheet to help you master regular expressions. 11 essential concepts are covered to help write regular expressions like a pro in no time.
In this week’s Tech Spotlight, a fascinating article from Dropbox’s Engineering team dives into the challenges faced due to clock skews!
*️⃣ 11 Rules for Regular Expressions
Basic Literal Matching
Match exact sequences of characters.
Example:
/helloWorld/
matches "helloWorld".Special characters may need to be escaped with a backslash.
Dot Wildcard
The dot (.) matches any single character, except for newline characters.
Example:
/ca./
matches "car", "cap", "can", "cat".
Anchors
Use anchors to match the start (^) or end ($) of a line.
Example:
/^success$/
matches "success".
Alternation
Use the pipe (|) to represent OR logic within a pattern.
Example:
/coffee|tea|milk/
matches "coffee", "tea", or "milk".
Groups & Parentheses
Group parts of the pattern using parentheses to capture or refer to them later.
Example:
/(hello|hi)world/
matches "hello world" or "hi world".
Character Classes
Match any one character from a defined set using square brackets [].
Example:
/gr[ae]y/
matches "gray" or "grey".Ranges like
[0-9]
match any digit, and[a-f]
matches hexadecimal digits.
Negated Character Classes
A caret (^) at the beginning of a character class negates it, matching any character not in the set.
Example:
/[^a-z]../
matches "Cat", "Dog", or "Car".
Quantifiers
Define the number of occurrences of a character or group.
Example:
/^\+[0-9]?[0-9]{11}$/
matches valid phone numbers.
Non-Capturing Groups
Use
(?:...)
to define a group without capturing it, improving performance.Example:
/^(?:hello) world$/
matches "hello world".
Back References
Match the same text as a previously captured group using
\1
,\2
, etc.Example:
/^([a-zA-Z]*)-\1$/
matches "boom-boom" or "Boom-Boom".
Assertions
Assertions verify conditions before or after a match, without including them in the final match.
Example:
/Alley(?=is cute)/
matches "Alley" but only if "is cute" follows.
» Checkout our Medium Blog for a deep-dive
🔦 Tech Spotlight!
At System Design Weekly, we’ve previously explored the challenges of clock skews, especially when it comes to getting them right in distributed systems. This week’s Tech Spotlight features a fascinating real-world case study from Dropbox, where clock skews led to unexpected bugs in their password manager.
➥ Fighting the forces of clock skew when syncing password payloads
Dropbox’s password management system stores passwords on client devices. Since users often have multiple devices (phone, tablet, laptop, etc.) connected to the same account, even a small clock skew can sometimes lead to lost updates. In this article, Dropbox’s engineers explain how they implemented a three-way merge strategy, similar to Git, to address this issue.
And that is it for this edition! If you enjoyed what you read, consider clicking the ❤️ button below and leaving a comment.
See you next week in yet another release of System Design Weekly! Till then, happy learning!