百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

regex-colorizer

> 后端框架
开源

用于 JavaScript 正则表达式语法的高亮器

199 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 JavaScript 正则表达式语法的高亮器

Regex Colorizer

npm version bundle

Regex Colorizer is a lightweight library (3.8 kB, with no dependencies) for adding syntax highlighting to your regular expressions in blogs, docs, regex testers, and other tools. It supports the JavaScript regex flavor (ES2023) with web reality. In other words, it highlights regexes as web browsers actually interpret them.

The API is simple. Just give the elements that contain your regexes (pre, code, or whatever) the class regex, and call colorizeAll(). See more usage examples below.

Errors are highlighted, along with some edge cases that can cause cross-browser grief. Hover over errors for a description of the problem.

Demo

Try it out on the demo page, which also includes more details.

️ Install and use

bash
npm install regex-colorizer
javascript
import {colorizeAll, loadStyles} from 'regex-colorizer';

Using a CDN and global name

xml

Examples

javascript
import {colorizeAll, colorizePattern, loadStyles} from 'regex-colorizer';

// Don't run this line if you provide your own stylesheet
loadStyles();

// Highlight all elements with class `regex`
colorizeAll();

// Or provide a `querySelectorAll` value for elements to highlight
colorizeAll({
  selector: '.regex',
});

// Optionally provide flags
colorizeAll({
  // Flags provided in `data-flags` attributes will override this
  flags: 'u',
});

// You can also just get the highlighting HTML for a specific pattern
element.innerHTML = colorizePattern('(?<=\\d)', {
  flags: 'u',
});

In your HTML:

xml

  This regex is highlighted inline:
  (?&lt;=\d)\p{L}\8.

  And here's the same regex but with different rules from flag u:
  (?&lt;=\d)\p{L}\8.
  

Themes

Several themes are available as stylesheets, but you don't need to add a stylesheet to your page to use the default theme. Just run loadStyles().

️ About

Regex Colorizer was created by Steven Levithan. It started in 2007 as part of RegexPal, the first web-based regex tester with regex syntax highlighting. It was extracted into a standalone library in 2010.

If you want to support this project, I'd love your help by contributing improvements, sharing it with others, or sponsoring ongoing development.

© 2007–present. MIT License.

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptregexregexpregular-expressionsyntax-highlighting

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架