Real World Maths Busters
The Maths Behind Everyday Life
The story, the formula and a worked example — see exactly where this maths shows up in the world around you.
Technology 3 min read
Finding Needles in Text Haystacks
Regular expressions match text patterns in milliseconds.
A regular expression (regex) is a pattern language for text. The pattern \d{3}-\d{4} matches any phone number like 555-1234. Computers execute these against millions of lines per second.
Pattern Complexity
Simple patterns match in O(n) time — one pass through the text. A regex checking a 1 million character document does about 1 million comparisons.
Searching a 10 MB text file
- 1
Characters
10 MB ≈ 10,000,000 characters
- 2
At 1 billion comparisons/sec
Answer
10 milliseconds to search the entire file
The takeaway
Regex turns pattern-matching into a single-pass operation — fast enough to search millions of characters instantly.