Hex Color Code Regex
Matches CSS hex color codes like #fff or #ffffff.
パターン
/#(?:[0-9a-fA-F]{3}){1,2}\b/g
→ ビジュアライザーで開くテスト例
Colors: #fff, #000000, #FF5733, #abc, #1a2b3c
コード例
javascript
const regex = /#(?:[0-9a-fA-F]{3}){1,2}\b/g;
const result = str.match(regex);python
import re
pattern = re.compile(r'#(?:[0-9a-fA-F]{3}){1,2}\b')
result = pattern.findall(text)go
import "regexp"
re := regexp.MustCompile(`#(?:[0-9a-fA-F]{3}){1,2}\b`)
result := re.FindAllString(text, -1)csscolorhex