Its biggest advantage can be summed up in three words: flexible, flexible, and flexible.
In daily development, regular expressions are everywhere — validating emails, phone numbers, URLs, ID cards, password strength, and more.
But every project and every file seems to have its own version of the same regex. It’s hard to maintain and easy to mess up.
For example:
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$/;
if (!emailRegex.test(email)) {
console.error('Invalid email format');
}
Or like this 👇
if (!/^1[3-9]\d{9}$/.test(phone)) {
alert('Invalid phone number');
}
Over time, the same regex appears in multiple forms across the codebase —
updating one means a global replace, and team standards become inconsistent.
Eventually, everyone’s asking the same question:
“Where did this regex even come from?”
That’s exactly what regex-center is built to solve.
Regex Center = Regex + Management
regex-center is a professional regex management library —
it comes with 100+ built-in patterns, supports custom extensions, team-wide management, type hints, and ReDoS-safe validation.
It’s not just for matching — you can also extract, replace, highlight, and mask text easily.
🔧 Core Features
- ✅ 100+ built-in common regex rules
- ✅ Named groups (e.g.
email:strict
,password:strong
) - ✅ Unified management and extensibility (
inject
,use
) - ✅ Full TypeScript support
- ✅ Built-in ReDoS protection
- ✅ Advanced text operations (extract, replace, highlight, count)
- ✅ Works in both browser and Node.js — zero dependencies
🚀 Quick Start
Installation
npm install regex-center
Option 1: Use built-in regex rules (plug and play)
// 100+ built-in rules covering all common cases
import { rx } from 'regex-center';
// Retrieve and validate
rx.get('email'); // → /^[^\s@]+@[^\s@]+\.[^\s@]+$/
rx.get('phone:CN'); // → /^1[3-9]\d{9}$/
rx.test('email', 'user@example.com'); // true
rx.test('phone:CN', '13800138000'); // true
rx.test(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, 'user@company.com'); // true
// Grouped rules
rx.test('password:strong', 'Password123!'); // strong password
rx.test('email:enterprise', 'user@company.com'); // enterprise email
// Text processing
const text = 'Contact: user@example.com, Phone: 13800138000';
rx.extractAll('phone:CN', text); // extract phone numbers
rx.replaceAll('phone:CN', text, '[PHONE]'); // replace phone numbers
rx.highlight('phone:CN', text, '<mark>$&</mark>'); // highlight
Option 2: Build a team-wide regex management system (recommended)
// Replace built-in regexes with your own team standards
rx.use({
email: /^[a-z0-9._%+-]+@company\.com$/, // only allow company emails
phone: {
default: 'mobile',
mobile: /^1[3-9]\d{9}$/, // mobile phone
landline: /^0\d{2,3}-?\d{7,8}$/ // landline
},
employeeId: {
pattern: /^EMP\d{6}$/,
description: 'Employee ID: EMP + 6 digits',
examples: {
valid: ['EMP123456', 'EMP000001'],
invalid: ['emp123456', 'EMP12345']
}
}
});
// Now only your team’s regex rules are available
rx.add('employeeId', /^EMP\d{6}$/);
rx.get('email'); // /^[a-z0-9._%+-]+@company\.com$/
rx.test('email', 'user@company.com'); // true
rx.test('email', 'user@gmail.com'); // false
rx.info('employeeId'); // view rule info
🧩 Custom Scenarios
Custom Rule Injection
Need to define your company’s domain rule?
rx.inject({
email: /^[a-z0-9._%+-]+@company.com$/,
});
rx.test('email', 'jack@company.com'); // true
rx.test('email', 'jack@gmail.com'); // false
Batch Operations
const text = 'Emails: a@b.com, c@d.com, e@f.com';
// Highlight all
rx.highlight('email', text, '<mark>$&</mark>');
// => Emails: <mark>a@b.com</mark>, <mark>c@d.com</mark>, <mark>e@f.com</mark>
// Count matches
rx.count('email', text); // 3
extractBatch
, replaceBatch
, and countBatch
are also available for more complex tasks.
Group Syntax
// Multiple formats for the same type — a unique feature of regex-center
// Password strength
rx.test('password:weak', '123456'); // weak
rx.test('password:medium', 'Password123'); // medium
rx.test('password:strong', 'Password123!'); // strong
// Email strictness
rx.test('email:basic', 'test@gmail.com'); // loose
rx.test('email:strict', 'user@company.com'); // RFC standard
rx.test('email:enterprise', 'admin@company.com'); // enterprise
// Numeric types
rx.test('number:integer', '123');
rx.test('number:decimal', '123.45');
rx.test('number:signed', '-123');
// View available groups
rx.info('password').groups; // ['weak', 'medium', 'strong']
⚡ Security & Performance
When injecting custom regex, regex-center
automatically scans for ReDoS vulnerabilities,
preventing performance issues caused by poorly written regex patterns.
Even under heavy text-matching loads, it remains safe and stable.
📚 Built-in Regex Examples
Type | Syntax | Description | Example |
---|---|---|---|
email / email:basic
|
Basic email | rx.test('email', 'user@example.com') |
|
email:strict |
RFC-standard email | rx.test('email:strict', 'user@company.com') |
|
email:enterprise |
Enterprise email | rx.test('email:enterprise', 'admin@company.com') |
|
Phone | phone:CN |
Chinese phone | rx.test('phone:CN', '13800138000') |
phone:US |
US phone | rx.test('phone:US', '+1-555-123-4567') |
|
ID Card | idCard:CN |
Chinese ID | rx.test('idCard:CN', '110101199003077777') |
Bank Card | bankCard:CN |
Chinese bank card | rx.test('bankCard:CN', '6222600260001234567') |
URL | url |
Basic URL | rx.test('url', 'https://example.com') |
IP | ip:v4 |
IPv4 | rx.test('ip:v4', '192.168.1.1') |
ip:v6 |
IPv6 | rx.test('ip:v6', '2001:db8::1') |
|
Number | number:integer |
Integer | rx.test('number:integer', '123') |
number:decimal |
Decimal | rx.test('number:decimal', '123.45') |
|
Date | date:YYYY-MM-DD |
Standard date | rx.test('date:YYYY-MM-DD', '2024-01-01') |
Password | password:medium |
Medium | rx.test('password:medium', 'Password123') |
password:strong |
Strong | rx.test('password:strong', 'Password123!') |
💡 Tip
-
email
defaults toemail:basic
. - For more patterns (e.g. hex, UUID, domain, color), check the Regex Reference.
🔍 How It Differs from Other Libraries
Feature / Library | validator.js | regexr.com | awesome-regex | regex-center |
---|---|---|---|---|
Focus | Validation functions | Online testing | Regex collections | Regex management and automation |
Usage | isEmail(str) |
Manual testing | Manual copy | rx.test('email', str) |
Built-in rules | 80+ | None | External links | 100+ + extensible system |
Custom rules | ❌ | ❌ | ❌ | ✅ via inject
|
Type hints | ❌ | ❌ | ❌ | ✅ TypeScript support |
Text tools | ❌ | ✅ Demo only | ❌ | ✅ extract / replace / highlight |
ReDoS protection | ❌ | ❌ | ❌ | ✅ automatic |
Ideal use case | Validation | Learning | Collection | Team-level regex standardization |
In short:
-
validator.js
is for simple business validation -
regexr
is for visualization and learning -
awesome-regex
is a regex index - regex-center is a “regex management platform” that unifies validation, testing, security, and extensibility
✅ Conclusion
Regular expressions shouldn’t become invisible technical debt.
regex-center turns regex from scattered snippets into a centralized, managed, and standardized system —
so you can use regex like any other utility function.
If your team struggles with regex maintenance or wants a unified regex standard,
give regex-center a try.
Top comments (0)