I wanted to check our codebase for where we had six repeating characters in HTML and CSS for colours, e.g. #FFFFFF for white. Here’s the regular expression for it, basically blogged here so I can remember where to find it later:
([a-fA-F0-9])1{5}
So [a-fA-F0-9] looks for a single character that is one of the letters A – F (only need to go up to F because we’re dealing with hexadecimal numbers), or the digits 0 – 9.
The ( ) parentheses around that turns it into a backreference.
The 1 then refers to that backreferenced matched, and the {5} says to match it exactly 5 times.
So it’ll find where there’s a single matching character that is then repeated five times.
What I was doing this for was to replace all six character codes (that repeat) for colours with three character codes (because #FFF is equivalent to #FFFFFF). So to…
View original post 92 more words