{"id":21214748,"url":"https://github.com/regexhq/hex-color-regex","last_synced_at":"2025-07-10T10:30:31.617Z","repository":{"id":26743027,"uuid":"30200724","full_name":"regexhq/hex-color-regex","owner":"regexhq","description":"Regular expression for matching hex color values from string.","archived":false,"fork":false,"pushed_at":"2017-06-03T01:32:22.000Z","size":34,"stargazers_count":33,"open_issues_count":1,"forks_count":6,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-14T08:53:09.458Z","etag":null,"topics":["colors","hex","hex-color","regex","regular-expression","web","web-colors"],"latest_commit_sha":null,"homepage":"http://j.mp/1EZWRUd","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/regexhq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-02T18:11:30.000Z","updated_at":"2024-07-31T19:34:45.000Z","dependencies_parsed_at":"2022-06-27T13:33:15.515Z","dependency_job_id":null,"html_url":"https://github.com/regexhq/hex-color-regex","commit_stats":null,"previous_names":["regexps/hex-color-regex"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexhq%2Fhex-color-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexhq%2Fhex-color-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexhq%2Fhex-color-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexhq%2Fhex-color-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/regexhq","download_url":"https://codeload.github.com/regexhq/hex-color-regex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225632559,"owners_count":17499815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["colors","hex","hex-color","regex","regular-expression","web","web-colors"],"created_at":"2024-11-20T21:30:37.344Z","updated_at":"2024-11-20T21:30:37.977Z","avatar_url":"https://github.com/regexhq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [hex-color-regex][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] \n\n\u003e The best regular expression (regex) for matching hex color values from string.\n\n[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coverage-img]][coverage-url] [![dependency status][david-img]][david-url]\n\n\n## Install\n```\nnpm i hex-color-regex --save\nnpm test\n```\n\n\n## Usage\n\u003e For more use-cases see the [tests](./test.js)\n\n- `[opts]` **{Object}** pass `strict: true` for strict mode\n- `return` **{RegExp}**\n\n**Example**\n\n```js\nvar hexColorRegex = require('hex-color-regex')\n\nhexColorRegex().test('#f3f}') //=\u003e true\nhexColorRegex({strict: true}).test('#f3f}') //=\u003e false\n\nhexColorRegex().test('foo #f3f bar') //=\u003e true\nhexColorRegex({strict: true}).test('foo #f3f bar') //=\u003e false\n\nhexColorRegex().test('#a54f2c}') //=\u003e true\nhexColorRegex({strict: true}).test('#a54f2c}') //=\u003e false\n\nhexColorRegex().test('foo #a54f2c bar') //=\u003e true\nhexColorRegex({strict: true}).test('foo #a54f2c bar') //=\u003e false\n\nhexColorRegex().test('#ffff') //=\u003e false\nhexColorRegex().test('ffff') //=\u003e false\n\nhexColorRegex().test('#fff') //=\u003e true\nhexColorRegex().test('fff') //=\u003e false\n\nhexColorRegex().test('#4g1') //=\u003e false\nhexColorRegex().test('4g1') //=\u003e false\nhexColorRegex().test('#zY1') //=\u003e false\nhexColorRegex().test('zY1') //=\u003e false\nhexColorRegex().test('#7f68ZY') //=\u003e false\nhexColorRegex().test('7f68ZY') //=\u003e false\nhexColorRegex().test('ffffff') //=\u003e false\n\nhexColorRegex().test('#afebe3') //=\u003e true\nhexColorRegex().test('#AFEBE3') //=\u003e true\nhexColorRegex().test('#3cb371') //=\u003e true\nhexColorRegex().test('#3CB371') //=\u003e true\nhexColorRegex().test('#556b2f') //=\u003e true\nhexColorRegex().test('#556B2F') //=\u003e true\nhexColorRegex().test('#708090') //=\u003e true\nhexColorRegex().test('#7b68ee') //=\u003e true\nhexColorRegex().test('#7B68EE') //=\u003e true\nhexColorRegex().test('#eeeeee') //=\u003e true\nhexColorRegex().test('#ffffff') //=\u003e true\nhexColorRegex().test('#111111') //=\u003e true\n\nhexColorRegex().test('#afe') //=\u003e true\nhexColorRegex().test('#AF3') //=\u003e true\nhexColorRegex().test('#3cb') //=\u003e true\nhexColorRegex().test('#3CB') //=\u003e true\nhexColorRegex().test('#b2f') //=\u003e true\nhexColorRegex().test('#5B2') //=\u003e true\nhexColorRegex().test('#708') //=\u003e true\nhexColorRegex().test('#68e') //=\u003e true\nhexColorRegex().test('#7AF') //=\u003e true\nhexColorRegex().test('#777') //=\u003e true\nhexColorRegex().test('#FFF') //=\u003e true\nhexColorRegex().test('#fff') //=\u003e true\n```\n\n\n## Matching groups\n\n- `match[0]` hex value with hash - `#f3f3f3`\n- `match[1]` hex value without the hash - `f3f3f3`\n\n**Example**\n\n```js\nhexColorRegex().exec('foo #fff bar')\n//=\u003e [ '#fff', 'fff', index: 4, input: 'foo #fff bar' ]\n\nhexColorRegex({strict: true}).exec('foo #fff bar')\n//=\u003e null\n\nhexColorRegex().exec('foo #f3f3f3 bar')\n//=\u003e [ '#f3f3f3', 'f3f3f3', index: 4, input: 'foo #f3f3f3 bar' ]\n\nhexColorRegex({strict: true}).exec('foo #f3f3f3 bar')\n//=\u003e null\n```\n\n\n## Related\n- [benz](https://github.com/tunnckocore/benz): Compose your control flow with absolute elegance. Support async/await, callbacks, thunks, generators, promises, observables, child… [more](https://github.com/tunnckocore/benz)\n- [is-hexcolor](https://github.com/tunnckocore/is-hexcolor): Check that given value is valid hex color, using `hex-color-regex` - the best regex for… [more](https://github.com/tunnckocore/is-hexcolor)\n- [is-ansi](https://github.com/tunnckocore/is-ansi): Check that given string contain ANSI color codes, without CLI\n- [is-missing](https://github.com/tunnckocore/is-missing): Check that given `name` or `user/repo` exists in npm registry or in github as user… [more](https://github.com/tunnckocore/is-missing)\n- [is-kindof](https://github.com/tunnckocore/is-kindof): Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper… [more](https://github.com/tunnckocore/is-kindof)\n- [is-typeof-error](https://github.com/tunnckocore/is-typeof-error): Check that given value is any type of error and instanceof Error\n- [is-async-function](https://github.com/tunnckocore/is-async-function): Check that given function is async (callback) function or not. Trying to guess that based… [more](https://github.com/tunnckocore/is-async-function)\n- [kind-error](https://github.com/tunnckocore/kind-error): Correct inheriting from `Error`. Supports constructing from an object of properties - focused on assertion.\n- [kind-of-extra](https://github.com/tunnckocore/kind-of-extra): Extends `kind-of` type check utility with support for promises, generators, streams and errors. Like `kindof(Promise.resolve(1))… [more](https://github.com/tunnckocore/kind-of-extra)\n- [vez](https://github.com/tunnckocore/vez): Middleware composition at new level. Ultimate alternative to `ware`, `plugins`, `koa-compose` and `composition` packages. Allows… [more](https://github.com/tunnckocore/vez)\n\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/regexhq/hex-color-regex/issues/new).  \nBut before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.\n\n\n## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]\n\n[![tunnckocore.tk][author-www-img]][author-www-url] [![keybase tunnckocore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]\n\n\n[npmjs-url]: https://www.npmjs.com/package/hex-color-regex\n[npmjs-img]: https://img.shields.io/npm/v/hex-color-regex.svg?label=hex-color-regex\n\n[license-url]: https://github.com/regexhq/hex-color-regex/blob/master/LICENSE.md\n[license-img]: https://img.shields.io/badge/license-MIT-blue.svg\n\n\n[codeclimate-url]: https://codeclimate.com/github/regexps/hex-color-regex\n[codeclimate-img]: https://img.shields.io/codeclimate/github/regexps/hex-color-regex.svg\n\n[coverage-url]: https://codeclimate.com/github/regexps/hex-color-regex\n[coverage-img]: https://img.shields.io/codeclimate/coverage/github/regexps/hex-color-regex.svg\n\n[travis-url]: https://travis-ci.org/regexhq/hex-color-regex\n[travis-img]: https://img.shields.io/travis/regexhq/hex-color-regex.svg\n\n[coveralls-url]: https://coveralls.io/r/regexhq/hex-color-regex\n[coveralls-img]: https://img.shields.io/coveralls/regexhq/hex-color-regex.svg\n\n[david-url]: https://david-dm.org/regexhq/hex-color-regex\n[david-img]: https://img.shields.io/david/dev/regexhq/hex-color-regex.svg\n\n[standard-url]: https://github.com/feross/standard\n[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n\n\n[author-www-url]: http://www.tunnckocore.tk\n[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg\n\n[keybase-url]: https://keybase.io/tunnckocore\n[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg\n\n[author-npm-url]: https://www.npmjs.com/~tunnckocore\n[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg\n\n[author-twitter-url]: https://twitter.com/tunnckoCore\n[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg\n\n[author-github-url]: https://github.com/tunnckoCore\n[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg\n\n[freenode-url]: http://webchat.freenode.net/?channels=charlike\n[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg\n\n[new-message-url]: https://github.com/tunnckoCore/messages\n[new-message-img]: https://img.shields.io/badge/send%20me-message-green.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregexhq%2Fhex-color-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fregexhq%2Fhex-color-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregexhq%2Fhex-color-regex/lists"}