Regular Expression
PronunciationREG-yoo-ler ik-SPRESH-un
Definition
A regular expression (regex) is a short pattern, written in a special syntax, used to search, match or extract parts of text.
Where you hear it
In text-processing code, input validation, log searching, and editor search-and-replace.
Examples
The regex extracts every number from the message.
I used a regular expression to validate the phone format.
The regular expression checks that the code looks like AB-1234.
Common mistake
Writing a huge regex nobody can read. Keep patterns small, add comments, and use a parser for complex formats such as HTML.
Don't confuse with
A plain text search, which looks for an exact string. A regex describes a pattern that can match many strings.
Say it at work
- In a meeting or chat
A short regex is enough for this check.
- In an email or ticket
Test the pattern against a few edge cases before merging.
Keep exploring
More in Programming Fundamentals