Hello Dev Community! ๐
It is officially Day 89 of my 100-day full-stack engineering run! ๐ฏ Yesterday, I kicked off my competitive solving streak on HackerRank. Today, I advanced from standard linear filters into the powerful world of textual pattern recognition by mastering: SQL Regular Expressions (REGEXP) and String Anchors! ๐๐ก๏ธ
When processing real-world data pipelinesโlike validating structured phone inputs, email domains, or parsing specific text queriesโstandard LIKE operators can make your code messy and repetitive. Today, I solved these constraints elegantly.
๐ง Shifting from Bulky LIKE Statements to Sleek REGEXP
As tracked inside my workspace files across "Screenshot (193).png" and "Screenshot (195).png", I solved two distinct core challenges from the HackerRank series:
1. Match from the Start: Weather Observation Station 6
-
The Goal: Query the list of
CITYnames fromSTATIONthat start with vowels (a,e,i,o,u), ensuring no duplicates are returned. -
The Evolution: Instead of chaining multiple
LIKEqueries or cutting sub-strings withLEFT(), I utilized the caret anchor (^) inside a regular expression array to verify the string's starting boundary instantly:
sql
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP "^(A|E|I|O|U)";
Top comments (0)