b3ta.com talk
You are not logged in. Login or Signup
Home » Talk » Message 614715

anyone here understand regexes?
i'm trying to learn it, and want to know why this:
^([0-9a-f]{1,2}){3}$

matches valid web colours.
i tried to concoct my own expression, but failed, so i googled, but i still need to know why this works.
(, Sun 3 Jul 2005, 17:26, archived)
I haven't a clue
and even if I did my head isn't working today. from my sickbed of the couch I've been doing sorting/packing and found some old maths paoers. apparently in 1989 I understood Mandelbrot
(, Sun 3 Jul 2005, 17:30, archived)
I've stared
at this post for a while now

and I still understand nowt :(
(, Sun 3 Jul 2005, 17:32, archived)
i have much the same feeling
it's a programming thing
regular-expressions.info/
(, Sun 3 Jul 2005, 17:34, archived)
phew!
that site flew straight over my head
(, Sun 3 Jul 2005, 17:47, archived)

/^#([0-9a-f]{1,2}){3}$/ says repeat any of the characters from 0-9 or a-f at least once but no more than twice. Then it says repeat the last grouped expression 3 times. So since the previous expression can be 1 or 2 this could mean that it would validate at 3,4,5, or 6 characters. I know i said 3 or 6 in my last post but I didn't think it all the way through. it could be between 3 and 6 characters. To validate only 6 characters try this

/^#[0-9a-f]{6}$/i


shameless c&p from this
(, Sun 3 Jul 2005, 17:32, archived)
i can just about see that
but i don't understand the use of ^ or $
(, Sun 3 Jul 2005, 17:35, archived)
I don't know anything about it,
but it looks like /^ and $/ mark the start and end of the rule used

edit: www.amk.ca/python/howto/regex/regex.html#SECTION000510000000000000000
(, Sun 3 Jul 2005, 17:39, archived)