Regex builder

From Sir-chawakorn/power-ranger-toolkit · View interactive version

Regex builder is an AI agent skill from the GitHub repository Sir-chawakorn/power-ranger-toolkit. Build and explain regular expressions from natural language descriptions

How to use this skill

Skill file

🔤 Regex Builder Skill


name: regex-builder

description: Build and explain regular expressions from natural language descriptions


🎯 Purpose

สร้าง Regular Expressions จาก natural language และอธิบาย regex ที่ซับซ้อนให้เข้าใจง่าย

📋 When to Use

🔧 Common Patterns

Email Validation

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Explanation:

Phone Number (Thai)

^(0[689]\d{8}|0[2-9]\d{7,8})$

Explanation:

URL

^https?:\/\/[^\s]+$

Date (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

Password (Strong)

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Explanation:

📊 Regex Cheat Sheet

Character Classes

| Pattern | Meaning |

|---------|---------|

| . | Any character (except newline) |

| \d | Digit (0-9) |

| \D | Non-digit |

| \w | Word character (a-z, A-Z, 0-9, _) |

| \W | Non-word character |

| \s | Whitespace |

| \S | Non-whitespace |

Quantifiers

| Pattern | Meaning |

|---------|---------|

| * | 0 or more |

| + | 1 or more |

| ? | 0 or 1 |

| {n} | Exactly n |

| {n,} | n or more |

| {n,m} | Between n and m |

Anchors

| Pattern | Meaning |

|---------|---------|

| ^ | Start of string |

| $ | End of string |

| \b | Word boundary |

Groups

| Pattern | Meaning |

|---------|---------|

| (...) | Capture group |

| (?:...) | Non-capture group |

| (?=...) | Positive lookahead |

| (?!...) | Negative lookahead |

📝 Natural Language → Regex

| Natural Language | Regex |

|-----------------|-------|

| "starts with A" | ^A |

| "ends with .com" | \.com$ |

| "contains numbers" | \d+ |

| "exactly 5 digits" | ^\d{5}$ |

| "optional dashes" | -? |

| "one or more words" | \w+ |

| "either cat or dog" | (cat\|dog) |

🔧 JavaScript Usage

// Test pattern
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
emailRegex.test('user@example.com'); // true

// Extract matches
const text = 'Call 081-234-5678 or 089-876-5432';
const phones = text.match(/0[689]\d-?\d{3}-?\d{4}/g);
// ['081-234-5678', '089-876-5432']

// Replace
const cleaned = text.replace(/[^\d]/g, '');
// '08123456780898765432'

// Named groups
const dateRegex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const match = '2024-01-15'.match(dateRegex);
console.log(match.groups.year); // '2024'

🔍 Regex Debugging

Test Online

Common Mistakes

| Mistake | Fix |

|---------|-----|

| Forgot to escape . | Use \. |

| Greedy matching | Use *? or +? |

| Missing anchors | Add ^ and $ |

| Global flag missing | Add g flag |

✅ Regex Checklist

🔗 Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.