Regular Expressions 101

Community Patterns

Hexadecimal Colour Code Finder

1

Regular Expression
PCRE2 (PHP >=7.3)

/
#[0-9a-f]{3}(?:[0-9a-f]{3})?(?=\W|$)
/
gm

Description

This regex will find any hexadecimal colour code, anywhere in your string

Support for: mini 3 letter codes normal 6 letter codes back to back codes

Submitted by anonymous - 7 months ago