Regex Cheat Sheet for Backend Developers
Regular expressions (regex) are very important for backend developers working with Node.js, Python, Java, and databases. Indian developers often use regex for validation of phone numbers, Aadhaar, PAN, GST, emails, and passwords.
👉 Try Regex Generator Tool → https://dev-brains-ai.com/regex-generator
1️⃣ Basic Regex Symbols
- . → Any character
- * → Zero or more
- + → One or more
- ? → Optional
- ^ → Start of string
- $ → End of string
Example: ^hello$
2️⃣ Character Classes
[abc] → a or b or c [a-z] → lowercase letters [A-Z] → uppercase letters [0-9] → digits [^0-9] → not digits \d → digit \w → word character \s → whitespace
3️⃣ Common Validation Regex
Email Validation
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$Indian Phone Number
^(\+91)?[6-9][0-9]{9}$PAN Card
^[A-Z]{5}[0-9]{4}[A-Z]$GST Number
^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$PIN Code
^[1-9][0-9]{5}$4️⃣ Regex in Node.js Example
const phoneRegex = /^(\+91)?[6-9][0-9]{9}$/;
console.log(phoneRegex.test("9876543210"));
Regex in Python
import re
pattern = r"^(\+91)?[6-9][0-9]{9}$"
print(re.match(pattern, "9876543210"))
5️⃣ Real Use Cases for Backend Developers
- Validate API input data
- Check password strength
- Extract log errors
- Parse CSV or JSON data
- Validate GST or PAN numbers
👉 Try JSON Formatter → https://dev-brains-ai.com/json-formatter
6️⃣ Regex Interview Questions in India
Companies like TCS, Infosys, and startups ask:- Write regex for email validation
- Find duplicate words in string
- Extract numbers from text
- Validate password rules
Tips to Master Regex
- Practice daily with real examples
- Test regex using online tools
- Start simple and build step-by-step
- Use comments to explain patterns
Conclusion
Regex is one of the most powerful skills for backend developers in India. It helps with validation, parsing, automation, and debugging.
Use Dev-Brains-AI tools to generate and test regex patterns faster.
👉 https://dev-brains-ai.com/