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.
The url-regex npm package is a utility for matching URLs in strings using regular expressions. It can be used to find and extract URLs from text, validate URLs, and more.
Match URLs in a string
This feature allows you to find and extract all URLs present in a given string.
const urlRegex = require('url-regex');
const text = 'Check out this link: https://example.com and this one: http://example.org';
const urls = text.match(urlRegex());
console.log(urls); // ['https://example.com', 'http://example.org']
Validate a URL
This feature allows you to validate if a given string is a valid URL.
const urlRegex = require('url-regex');
const isValidUrl = urlRegex({ exact: true }).test('https://example.com');
console.log(isValidUrl); // true
Match URLs with specific protocols
This feature allows you to match URLs with specific protocols, such as 'https' or 'ftp'.
const urlRegex = require('url-regex');
const text = 'Visit our site at https://example.com or our FTP server at ftp://example.org';
const urls = text.match(urlRegex({ protocols: ['https'] }));
console.log(urls); // ['https://example.com']
linkify-it is a fast and lightweight library for finding and converting URLs in plain text into clickable links. It offers more customization options compared to url-regex, such as handling different types of links (e.g., email addresses) and providing hooks for custom link processing.
url-pattern is a utility for matching URLs against patterns. It is more focused on URL routing and matching specific URL structures, making it useful for applications like client-side routing in single-page applications. It offers more flexibility in defining and matching complex URL patterns compared to url-regex.
valid-url is a simple utility for validating URLs. It provides functions to check if a URL is valid, if it is a web URL, or if it is an HTTP/HTTPS URL. It is more focused on validation rather than extraction, making it a good choice for scenarios where URL validation is the primary requirement.
Regular expression for matching URLs
Based on this gist by Diego Perini.
$ npm install --save url-regex
var urlRegex = require('url-regex');
urlRegex().test('https://github.com');
//=> true
urlRegex().exec('This is a cool site https://github.com')[0].trim();
//=> https://github.com
'Multiple https://github.com http://google.com URLs'.match(urlRegex());
//=> ['https://github.com', 'http://google.com']
MIT © Diego Perini
FAQs
Regular expression for matching URLs
We found that url-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.