我正在为这种字符串寻找一些正则表达式
rgb(r,g,b)
rgba(r,g,b,a)
hsl(h,s%,l%)
hsla(h,s%,l%,a)
和:
r,g,b integer included between 0 and 255,
a float between 0 and 1 (truncated to first digit after the point)
h integer included between 0 and 359
s,l integer included between 0 and 100
对于 rgb,我写了那些正则表达式:
rgb\(\s*((?:[0-2]?[0-9])?[0-9])\s*,\s*((?:[0-2]?[0-9])?[0-9])\s*,\s*((?:[0-2]?[0-9])?[0-9])\s*\)$
它可以工作,但它也允许像 rgb(299,299,299) 这样的字符串。我怎样才能使它更有效?那么rgba,hsl和hsla呢?谢谢