
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
The rgb-regex package provides a regular expression for matching RGB color strings in text. It can be used to find and manipulate RGB color strings within strings of text in JavaScript applications.
Matching RGB strings
This feature allows you to match RGB color strings in a given text. The code sample demonstrates how to use the rgb-regex package to find an RGB string within a larger string.
const rgbRegex = require('rgb-regex');
const text = 'background: rgb(12, 34, 56);';
const match = text.match(rgbRegex());
console.log(match[0]); // 'rgb(12, 34, 56)'
Matching RGB strings with exact option
This feature allows you to match an exact RGB string without any additional characters. The code sample shows how to use the rgb-regex package to test for an exact RGB string match.
const rgbRegex = require('rgb-regex');
const exactMatch = 'rgb(12, 34, 56)';
const isExactMatch = rgbRegex({ exact: true }).test(exactMatch);
console.log(isExactMatch); // true
The color-regex package provides regular expressions for matching color strings, including RGB, HEX, HSL, and more. It offers a broader range of color string matching compared to rgb-regex, which focuses solely on RGB.
The hex-color-regex package is specifically designed to match HEX color strings. While rgb-regex is for RGB color strings, hex-color-regex serves a similar purpose for a different color format.
Similar to rgb-regex, rgba-regex is designed to match RGBA color strings, which include an alpha channel for opacity. It is useful for cases where transparency needs to be considered in addition to RGB colors.
Regex for RGB color strings.
npm install --save rgb-regex
var rgbRegex = require('rgb-regex');
rgbRegex({ exact: true }).test('rgb(12, 34, 56)'); // => true
rgbRegex({ exact: true }).test('unicorns'); // -> false
rgbRegex({ exact: true }).test('rgb(,,)'); // => false
rgbRegex().exec('rgb(12, 34, 56)');
// => [
// '12',
// '34',
// '56',
// index: 0,
// input: 'rgb(12,34,56)'
// ]
'rgb(12, 34, 56) cats and dogs'.match(rgbRegex());
// = ['rgb(12, 34, 56)']
MIT
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Crafted with <3 by John Otander (@4lpine).
This package was initially generated with yeoman and the p generator.
FAQs
Regex for RGB color strings.
The npm package rgb-regex receives a total of 2,110,001 weekly downloads. As such, rgb-regex popularity was classified as popular.
We found that rgb-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.