I need a regular expression to convert 3-digit hex color codes in html to 6 digit ones. I want to do this because when I put html text into swing text components, the 3-digit versions don't seem to be recognised. I know how the 3-digit codes work by the way - the 3-digit code "#ABC;" is the same as the 6-digit code "#AABBCC;". I'm looking for a regex to do that simple conversion and expand/replace all instances in a given string.
Just to show some sort of effort on my part, I think this might find 3-digit color codes:
Code:
String s = html.replaceAll("#[0-9a-fA-F]{3};","????");
In case you're wondering, this is not a homework assignment. I've been programming for many years but have managed to spoof my way thus far with little or no grasp of regular expressions. They just are something I've never really gotten my head around! As a work-around, I started writing a 'simple' method to loop through the string looking for # symbols and what comes after them, yadda, yadda, yadda... but it got very large and ugly and I don't trust it. Plus, it's Monday and I'm just not up for that kind of thing

Thanks,
Brian





