Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
(#([a-f\d]{3}){1,2}\b)|(rgb\((((\s*(0*?[0-2][0-5][0-5]|1\d{2}|\d{1,2})\s*,){2}\s*(0*?[0-2][0-5][0-5]|1\d{2}|\d{1,2}))|((\s*(0*?(100|\d{1,2})(\.\d+)?\%)\s*,){2}\s*(0*?(100|\d{1,2})(\.\d+)?\%)))\s*\))|(rgba\(\s*(((\s*(0*?[0-2][0-5][0-5]|1\d{2}|\d{1,2})\s*,){3}|(\s*(0*?(100|\d{1,2})(\.\d+)?\%)\s*,){3})(\s*0+(\.\d+)?\s*))\s*\))|(hsl\(\s*((0*?([0-3][0-6]0|\d{1,2}))\s*(,\s*(0*?(100|\d{1,2})(\.\d+)?\%)\s*){2})\))|(hsla\(\s*((0*?([0-3][0-6]0|\d{1,2}))\s*,(\s*(0*?(100|\d{1,2})(\.\d+)?\%)\s*,){2})\s*(0+(\.\d+)?)\s*\))
/
gmi
Input 1
1
New
Should match 3 ou 6 digits hexadecimal numbers #fff #FFF #Fff #ff004B All numerical values can have leading zeros. Percentages can have decimals. White spaces are allowed before and after values. Should match rgb() colors with 3 values all between 0 and 255 rgb(150,0,0) RGB(00124, 100, 0 ) rGb(255,255,255) Rgb( 0255, 00001, 00002) rgb(159,0,0) rgb(0,199,99) Should match rgb() colors using percentages all between 0 and 100 rgb( 10%,10%,10%) rgb(100.0%, 2.5%, 0%) rgb(00010%, 0002%, 001%) Should match rgba() colors with 3 values between 0 and 255 plus 1 decimal value between 0 and 1 rgba(255 , 0 , 0, 0.5 ) rgba(1,1,1,0.255) rgba(0,0,0,0) Should match rgba() colors using 3 percentage values between 0 and 100 plus 1 decimal value between 0 and 1 rgba(10%,10% , 10%, 0.2) rgba(10%, 0025.2%, 1%, 0.0001) Should match hsl() colors with first value between 0 and 360 and 2 more percentage values between 0 and 100 hsl(0,20%,100%) HsL( 360,10% , 0.2% ) hsl(000350, 002%, 0004.1%) Should match hsl() colors with first value between 0 and 360 and 2 more percentage values between 0 and 100 plus 1 decimal value between 0 and 1 hsla(140,2%,50%,0.2) hsla(0,0%,0%,0) hsla(001,002%,00001.2%,0000.254) Should NOT match hexadecimal numbers with not exactly 3 or 6 digits #f #ff #ffff #fffff #fffffff Should NOT match invalid hexadecimal values #ffg #fffffg Should NOT allow space between function and opening parenthesis rgb (0,0,0) rgba (0,0,0,0) rgb (0%,0%,0%) rgba (0%,0%,0%,0) hsl (0,0%,0%) hsla (0,0%,0%,0) Should NOT match rgb() nor hsl() colors with more or less than 3 values rgb(0,0,0,0) rgb(0,0) hsl(0,0%,0%,0) hsl(0,0%) Should NOT match rgba() nor hsla() colors with more or less than 4 values rgba(0,0,0) rgba(0,0,0,0,0) hsla(0,0%,0%) hsla(0,0%,0%,0,0) Should NOT allow rgb values over 255, nor rgb values with decimals rgb(256,0,0) rgb(100.2,0,0) Should NOT allow percentages over 100 rgb(120%,10%,1%) hsl(200, 101%, 10%) Should NOT allow alpha values over 1 rgba(0,0,0,1.2) hsla(120, 50%, 50%, 1.3) Should NOT allow hue values over 360 hsl(361,50%,50%) hsla(361,50%,50%,0.5) Should NOT match invalid hsl format hsl(1%,2%,3%) hsl(5,6,7) Should NOT match rgb() colors with mixed percentages and integers rgb(255, 10%, 0) rgb(10%, 255, 0) rgba(10%, 255, 0, 0.3)
Extraction
Should match 3 ou 6 digits hexadecimal numbers #fff #FFF #Fff #ff004B All numerical values can have leading zeros. Percentages can have decimals. White spaces are allowed before and after values. Should match rgb() colors with 3 values all between 0 and 255 rgb(150,0,0) RGB(00124, 100, 0 ) rGb(255,255,255) Rgb( 0255, 00001, 00002) rgb(159,0,0) rgb(0,199,99) Should match rgb() colors using percentages all between 0 and 100 rgb( 10%,10%,10%) rgb(100.0%, 2.5%, 0%) rgb(00010%, 0002%, 001%) Should match rgba() colors with 3 values between 0 and 255 plus 1 decimal value between 0 and 1 rgba(255 , 0 , 0, 0.5 ) rgba(1,1,1,0.255) rgba(0,0,0,0) Should match rgba() colors using 3 percentage values between 0 and 100 plus 1 decimal value between 0 and 1 rgba(10%,10% , 10%, 0.2) rgba(10%, 0025.2%, 1%, 0.0001) Should match hsl() colors with first value between 0 and 360 and 2 more percentage values between 0 and 100 hsl(0,20%,100%) HsL( 360,10% , 0.2% ) hsl(000350, 002%, 0004.1%) Should match hsl() colors with first value between 0 and 360 and 2 more percentage values between 0 and 100 plus 1 decimal value between 0 and 1 hsla(140,2%,50%,0.2) hsla(0,0%,0%,0) hsla(001,002%,00001.2%,0000.254) Should NOT match hexadecimal numbers with not exactly 3 or 6 digits #f #ff #ffff #fffff #fffffff Should NOT match invalid hexadecimal values #ffg #fffffg Should NOT allow space between function and opening parenthesis rgb (0,0,0) rgba (0,0,0,0) rgb (0%,0%,0%) rgba (0%,0%,0%,0) hsl (0,0%,0%) hsla (0,0%,0%,0) Should NOT match rgb() nor hsl() colors with more or less than 3 values rgb(0,0,0,0) rgb(0,0) hsl(0,0%,0%,0) hsl(0,0%) Should NOT match rgba() nor hsla() colors with more or less than 4 values rgba(0,0,0) rgba(0,0,0,0,0) hsla(0,0%,0%) hsla(0,0%,0%,0,0) Should NOT allow rgb values over 255, nor rgb values with decimals rgb(256,0,0) rgb(100.2,0,0) Should NOT allow percentages over 100 rgb(120%,10%,1%) hsl(200, 101%, 10%) Should NOT allow alpha values over 1 rgba(0,0,0,1.2) hsla(120, 50%, 50%, 1.3) Should NOT allow hue values over 360 hsl(361,50%,50%) hsla(361,50%,50%,0.5) Should NOT match invalid hsl format hsl(1%,2%,3%) hsl(5,6,7) Should NOT match rgb() colors with mixed percentages and integers rgb(255, 10%, 0) rgb(10%, 255, 0) rgba(10%, 255, 0, 0.3)