简体   繁体   中英

Regular expression to match Style sheet pattern

I would like to write a regular expression to match the following patters

CSS color words such as blue,black ,etc
Hexa decimal color codes

How to generate a regular expression to match the above said patterns?

Edit I would like to check only the following colors

aqua
black
blue
fuchsia
gray
green
lime
maroon

Google gives the following result

Regular expression for CSS Colors

I am not sure whether you are looking for similar patters.But at least it will give you some hints.

Try something like this:

#[0-9A-F]{3,8}|aqua|black|blue|fuchsia|gray|green|lime|maroon

You could also drop this regex (bad idea, IMHO) and stick with ColorTranslator.FromHtml Method

(maroon|aqua)|(#([0-9a-fA-F]{3}){1,2})

put the color names in the first section, separated by the | character

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM