gitmyhub

any-rule

TypeScript ★ 8.7k updated 1y ago

🦕 常用正则大全, 支持web / vscode / idea / Alfred Workflow多平台

A VS Code extension (and web app) bundling 84 pre-tested regular expressions for common formats like phone numbers, emails, Chinese IDs, and URLs, search by keyword and insert the pattern without writing it yourself.

TypeScriptsetup: easycomplexity 1/5

Any-rule is a collection of 84 common regular expressions, packaged as a VS Code extension with support for several other tools as well. A regular expression is a pattern that tells a program what a piece of text should look like, such as what a valid phone number, email address, or date format looks like. Writing these patterns correctly is tedious and error-prone, so having a pre-tested library of them saves developers time.

The VS Code extension offers three ways to insert a pattern into your code. You can open the command palette with F1 and type a keyword like "phone" or "date" to search the list. You can right-click anywhere in your editor to open the full catalog. Or you can type the shortcut @zz inline while writing code and pick from the dropdown that appears. Once you select a pattern, VS Code inserts it at the cursor.

The extension also includes a visual explanation feature. After selecting a pattern, a prompt lets you open a diagram showing how each part of the expression works, powered by the regexper.com tool. This makes the patterns easier to read and verify before using them.

Beyond VS Code, the same collection is available as a web app, a JetBrains IDEA plugin, an Alfred Workflow for macOS, a command-line tool, and a uTools plugin. These are maintained by separate contributors rather than the original author.

The patterns in the collection cover Chinese-specific formats like national ID card numbers, vehicle license plates (including new-energy plates), Chinese mobile phone numbers per official carrier data, and Chinese company credit codes. It also includes general formats like email addresses, URLs, IP addresses, dates, and file paths for both Windows and Linux systems. New patterns can be contributed via pull request by adding them to the rules file and running the included tests.

Where it fits