Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
pcre-to-regexp
Advanced tools
Creates a JavaScript RegExp
instance from a PCRE regexp string.
Not currently feature-complete, but works enough for my needs. Send
pull requests for additional functionality!
Works with Node.js and in the browser via a CommonJS bundler like browserify.
$ npm install pcre-to-regexp
A basic example of a Twitter URL parsing PCRE regexp:
var url = "%^https?:\/\/twitter\\.com(\/\\#\\!)?\/(?P<username>[a-zA-Z0-9_]{1,20})\\\/status(es)?\/(?P<id>\\d+)\/?$%ig";
// parse the PCRE regexp into a JS RegExp
var keys = [];
var re = PCRE(url, keys);
console.log(keys);
// [ , 'username', , 'id' ]
console.log(re);
// /^https?://twitter\.com(/\#\!)?/([a-zA-Z0-9_]{1,20})\/status(es)?/(\d+)/?$/gi
var match = re.exec('https://twitter.com/tootallnate/status/481604870626349056');
console.log(match);
// [ 'https://twitter.com/tootallnate/status/481604870626349056',
// undefined,
// 'tootallnate',
// undefined,
// '481604870626349056',
// index: 0,
// input: 'https://twitter.com/tootallnate/status/481604870626349056' ]
Use code like this if you would like to transfer the "named captures" to the
match
object:
// example of copying the named captures as keys on the `match` object
for (var i = 0; i < keys.length; i++) {
if ('string' === typeof keys[i]) {
match[keys[i]] = match[i + 1];
}
}
console.log(match.username);
// 'tootallnate'
console.log(match.id);
// '481604870626349056'
Returns a JavaScript RegExp instance from the given PCRE-compatible string.
Flags may be passed in after the final delimiter in the format
string.
An empty array may be passsed in as the second argument, which will be populated with the "named capture group" names as Strings in the Array, once the RegExp has been returned.
FAQs
Converts PCRE regexp strings to JavaScript RegExp instances
The npm package pcre-to-regexp receives a total of 60,076 weekly downloads. As such, pcre-to-regexp popularity was classified as popular.
We found that pcre-to-regexp 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.