const hexPattern =
/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
hexPattern.test('#FF0000'); // true
hexPattern.test('#f00'); // true (shorthand)
hexPattern.test('banana'); // false
hexPattern.test('#GGGGGG'); // false
const rgbPattern =
/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
function sanitizeFilename(name) {
return name
.replace(/[<>:"/\\|?*\x00-\x1F]/g, '')
.replace(/\s+/g, '_')
.replace(/_{2,}/g, '_')
.trim();
}
// "My Photo!!.png" → "My_Photo!!.png"
// "file<>:name.jpg" → "filename.jpg"
function searchFilters(filters, query) {
const pattern = new RegExp(query, 'i');
return filters.filter(f => pattern.test(f.name));
}
// searchFilters(allFilters, 'bright')
// → [BrightnessFilter]
Wire it all together: validate the color picker input, sanitize export filenames (from Session 25), and add regex-powered search to the filter tools panel.
git switch -c feature/PIXELCRAFT-027-regex-validation
git add src/scripts/
git commit -m "Add regex validation for colors and filenames (PIXELCRAFT-027)"
git push origin feature/PIXELCRAFT-027-regex-validation
# PR → Review → Merge → Close ticket ✅
Regular expressions are formally equivalent to finite automata.
One of the foundational concepts in CS theory.