Forum Moderators: coopster

Message Too Old, No Replies

(Mostly) working hexadecimal regex.

Need to match 3 *or* 6 (not 3-6) and 'transparent'.

         

JAB Creations

11:38 pm on May 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is my current regex string...
$regex_a = '/^([0-9a-f]{1,2}){3}$/';

Somehow this matches 3 or 6 characters in length which is what I want it to be able to match.

There are two other things I want to add support for...

1.) Exactly 'transparent' (and I will create a very similar copy for background-image support to support exactly 'none'.

2.) I'd like to also allow {0} in length however when I add the solid pipe(s) it breaks what I do have working!

Suggestions please?

- John

jdMorgan

12:13 am on May 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(x)? makes 'x' optional -- It accepts either 'x' or zero characters.

$regex_a = '/^(([0-9a-f]{1,2}){3}¦transparent¦none)?$/';

Jim

JAB Creations

12:37 am on May 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you Jim! Another working example helps me see how child parenthesis makes a pattern optional...

$regex_a = '/^(([a-f0-9]{3})¦([a-f0-9]{6}))$/';

This works great! Here is what I'm going with (broken pipes reminder and the image regex only matches the file's number as the extension is added elsewhere)...

$regex_color = '/^(([0-9a-f]{1,2}){3}¦transparent)?$/';
$regex_image = '/^(([0-9a-f]{1,2}){3}¦none)?$/';