Skip to content
Go back

正则表达式速查与实用案例

Updated:
Edit page

null

Table of contents

Open Table of contents

基础语法速览

符号含义示例
.匹配任意单个字符(换行符除外)a.b → acb
^匹配字符串开头^abc
$匹配字符串结尾xyz$
[]字符集[0-9] 匹配数字
()分组(abc)+
?可选colou?r 匹配 color 或 colour
*0 次或多次a*
+1 次或多次a+
{n,m}次数范围a{2,4} → aa、aaa、aaaa

常用正则表达式合集

字符与文本处理

数字与货币

日期与时间

URL 与路径

去除重复斜杠(除协议部分)

JavaScript 使用案例

const regex = /([^:]\/)\/+/g;
const domain = "https://example.com//notes/".replace(regex, "$1"); // https://example.com/notes/

邮箱与账号

HTML/XML

正则调试与工具

参考资料


Edit page
Share this post on:

Next Post
Powershell101