Skip to content
Back to skills

Docs

ASecurity

> 文章片段来源:https://github.com/ziishaned/learn-regex/blob/master/translations/README-cn.md 先行断言和后发断言都属于**非捕获簇**(不捕获文本 ,也不针对组合计进行计数). 先行断言用于判断所匹配的格式是否在另一个确定的格式之前, 匹配结果不包含该确定格式(仅作为约束). 例如, 我们想要获得所有跟在 `$` 符号后的数字, 我们可以使用正后发断言 `(?<=\$)[0-9\.]*`. 这个表达式匹配 `$` 开头, 之后跟着 `0,1,2,3,4,5,6,7,8,9,.` 这些字符可以出现大于等于 0 次. 零宽度断言如下: | 符号 | 描述 | | :--: | --------------- | | ?= | 正先行断言-存在 | | ?! | 负先行断言-排除 | | ?<= | 正后发断言-存在 | | ?<! | 负后发断言-排除 | `?=...` 正先行断言, 表示第一部分表达式之后必须跟着 `?=

  • 3 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 8, 2026
developmentgit

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add LinkXSystem/learn-guide --skill docs --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docs?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docs
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/linkxsystem-docs-learn-guide/badge)](https://www.skillsdirectory.com/skills/linkxsystem-docs-learn-guide)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 正则技巧

## 零宽度断言(前后预查)

> 文章片段来源:https://github.com/ziishaned/learn-regex/blob/master/translations/README-cn.md

先行断言和后发断言都属于**非捕获簇**(不捕获文本 ,也不针对组合计进行计数).
先行断言用于判断所匹配的格式是否在另一个确定的格式之前, 匹配结果不包含该确定格式(仅作为约束).

例如, 我们想要获得所有跟在 `$` 符号后的数字, 我们可以使用正后发断言 `(?<=\$)[0-9\.]*`.
这个表达式匹配 `$` 开头, 之后跟着 `0,1,2,3,4,5,6,7,8,9,.` 这些字符可以出现大于等于 0 次.

零宽度断言如下:

| 符号 | 描述            |
| :--: | --------------- |
|  ?=  | 正先行断言-存在 |
|  ?!  | 负先行断言-排除 |
| ?<=  | 正后发断言-存在 |
| ?<!  | 负后发断言-排除 |

### `?=...` 正先行断言

`?=...` 正先行断言, 表示第一部分表达式之后必须跟着 `?=...`定义的表达式.

返回结果只包含满足匹配条件的第一部分表达式.
定义一个正先行断言要使用 `()`. 在括号内部使用一个问号和等号: `(?=...)`.

正先行断言的内容写在括号中的等号后面.
例如, 表达式 `(T|t)he(?=\sfat)` 匹配 `The` 和 `the`, 在括号中我们又定义了正先行断言 `(?=\sfat)` ,即 `The` 和 `the` 后面紧跟着 `(空格)fat`.

<pre>
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
</pre>

### `?!...` 负先行断言

负先行断言 `?!` 用于筛选所有匹配结果, 筛选条件为 其后不跟随着断言中定义的格式.
`正先行断言` 定义和 `负先行断言` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`.

表达式 `(T|t)he(?!\sfat)` 匹配 `The` 和 `the`, 且其后不跟着 `(空格)fat`.

<pre>
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
</pre>

### `?<= ...` 正后发断言

正后发断言 记作`(?<=...)` 用于筛选所有匹配结果, 筛选条件为 其前跟随着断言中定义的格式.
例如, 表达式 `(?<=(T|t)he\s)(fat|mat)` 匹配 `fat` 和 `mat`, 且其前跟着 `The` 或 `the`.

<pre>
"(?<=(T|t)he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
</pre>

### `?<!...` 负后发断言

负后发断言 记作 `(?<!...)` 用于筛选所有匹配结果, 筛选条件为 其前不跟随着断言中定义的格式.
例如, 表达式 `(?<!(T|t)he\s)(cat)` 匹配 `cat`, 且其前不跟着 `The` 或 `the`.

<pre>
"(?&lt;!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
</pre>

Files in this skill

  • Binary Data Format.md1.1 KB
  • D8.md811 B
  • DOM Enlightenment.md2.8 KB
  • Dataset Skill.md1.3 KB
  • Design Of Protocol.md2.5 KB
  • Fetch.md979 B
  • NVS Tutorial.md2.6 KB
  • Regular Skill.md2.7 KB
  • Tsconfig.md3.4 KB
  • Webpack & Typescript.md3.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.