Regex for matching CSS hex colors

后端 未结 5 1075
傲寒
傲寒 2021-02-02 07:33

I\'m trying to write regex that extracts all hex colors from CSS code.

This is what I have now:

Code:

$css = <<

        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 08:28

    Shorter version of GolezTrol's answer that avoids writing the character set twice:

    /#([a-fA-F0-9]{3}){1,2}\b/
    

提交回复
热议问题