Regular expression (regex) for matching hex color values from string.
npm i --save hex-color-regex npm test
default: false
Tests also to see if the hex is the only token passed in (adds ^ to the beginning and $ to the end.)
For more use-cases see the tests
var hexColorRegex = require('hex-color-regex'); hexColorRegex().test('#f3f}') //=> false, for now hexColorRegex().test('#4g1') //=> false hexColorRegex().test('#zY1') //=> false hexColorRegex().test('111') //=> false hexColorRegex().test('fff') //=> false hexColorRegex().test('#7f68ZY') //=> false hexColorRegex().test('#GR68') //=> false hexColorRegex().test('#abcd') //=> false hexColorRegex().test('abcd') //=> false hexColorRegex().test('708135') //=> false hexColorRegex().test('ffffff') //=> false hexColorRegex().test('afebef') //=> false hexColorRegex().test('#113141}') //=> false, for now hexColorRegex({strict:true}).test('http://www.example.com/index.html#f06d06}') //=> false hexColorRegex().test('#afebe3') //=> true hexColorRegex().test('#AFEBE3') //=> true hexColorRegex().test('#3cb371') //=> true hexColorRegex().test('#3CB371') //=> true hexColorRegex().test('#556b2f') //=> true hexColorRegex().test('#556B2F') //=> true hexColorRegex().test('#708090') //=> true hexColorRegex().test('#7b68ee') //=> true hexColorRegex().test('#7B68EE') //=> true hexColorRegex().test('#eeeeee') //=> true hexColorRegex().test('#ffffff') //=> true hexColorRegex().test('#111111') //=> true hexColorRegex().test('#afe') //=> true hexColorRegex().test('#AF3') //=> true hexColorRegex().test('#3cb') //=> true hexColorRegex().test('#3CB') //=> true hexColorRegex().test('#b2f') //=> true hexColorRegex().test('#5B2') //=> true hexColorRegex().test('#708') //=> true hexColorRegex().test('#68e') //=> true hexColorRegex().test('#7AF') //=> true hexColorRegex().test('#777') //=> true hexColorRegex().test('#FFF') //=> true hexColorRegex().test('#fff') //=> true
hexColorRegex().exec('#a1b2c3'); //=> ['#a1b2c3', 'a1b2c3', index: 0, input: '#a1b2c3']
[0]
with the hash sign (#afafaf
)[1]
without hash sign (afafaf
)
Charlike Mike Reagent
Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Released under the MIT
license.
Powered and automated by kdf, February 3, 2015