Regular Expressions are shortcode langauge settings for computer programming used in cybersecurity. This was a LinkedIn Course that I did as part of my Masterschool studies
According to Grok:
Regular expressions (often abbreviated as regex or regexp) are a powerful, concise way to describe and match patterns in text. They are essentially a mini-programming language for searching, validating, extracting, or replacing strings based on specific rules.
Common Symbols & Syntax
| Symbol | Meaning | Example | Matches |
|---|---|---|---|
| . | Any single character (except newline) | c.t | cat, cot, c3t |
| * | Zero or more of the previous | ca*t | ct, cat, caat, caaat |
| + | One or more of the previous | ca+t | cat, caat, caaat (but not ct) |
| ? | Zero or one of the previous | ca?t | ct, cat |
| ^ | Start of string/line | ^Hello | “Hello world” ✓, “Say Hello” ✗ |
| $ | End of string/line | world$ | “Hello world” ✓ |
| [] | Character class (any one inside) | [aeiou] | any vowel |
| [^] | Negated class | [^0-9] | any non-digit |
| | | OR | cat|dog | cat or dog |
| () | Grouping / capture | (ab)+ | ab, abab, ababab |
| \d | Digit [0-9] | \d{3} | 123, 456 |
| \w | Word character [a-zA-Z0-9_] | \w+ | hello, var123 |
| \s | Whitespace (space, tab, etc.) | \s+ | one or more spaces |
| {n} | Exactly n times | \d{3} | exactly 3 digits |
| {n,} | n or more | \d{2,} | 2+ digits |
| {n,m} | Between n and m | \d{2,4} | 2–4 digits |
Real-World Examples
| Goal | Regex Pattern | Matches |
|---|---|---|
| Find emails | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | [email protected] |
| US phone (XXX-XXX-XXXX) | \d{3}-\d{3}-\d{4} | 123-456-7890 |
| HTML tag | <[^>]+> | <p>, <div class=”x”> |
| Date (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} | 2025-10-31 |
| Extract numbers | \d+ | all sequences of digits |
Where Are Regex Used?
- Programming: Python (re module), JavaScript, Java, PHP, etc.
- Tools: grep, sed, awk, VS Code search, Notepad++, Google Analytics
- Validation: Forms, password strength, input sanitization
Example in Python
python
import re
text = "Contact: [email protected] or [email protected]"
pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
emails = re.findall(pattern, text)
print(emails) # ['[email protected]', '[email protected]']
Discover more from Wez G Official Website
Subscribe to get the latest posts sent to your email.

