Skip to content

Instantly share code, notes, and snippets.

Explanation of regex: hex number selector

This gist explains a regex that selects certain number in hexadecimal format. This regex will select either 6 digits or 3 digits number in hexadecimal format, such as: #000000, #000, #ffffff, #fff.In most applications this can be used to select the css color code since they are coded in hexadecimal format and started with ‘#’.

Summary

The regex used in this explanation is /^#?([a-f0-9]{6}|[a-f0-9]{3})$/, this regex will be break into several parts based on its type, and explained separately.

Table of Contents

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database