# 前言

从 JavaScript 程序员的角度总结思考，循序渐进的学习正则表达式

## 关于本书

* [在线阅读](https://nxtech.gitbook.io/regexp/)（本书使用Gitbook编写）
* 本书适合人群：初学者与想系统性再次学习正则者
* 读者发现文章问题，可直接在页面下方评论，或联系笔者（<yorkyu18@gmail.com>）修正
* 作者：Yorkyu

本书是作者在学习Regexp后整理的学习笔记，希望对读者有所帮助

随着笔者对Regexp的深入理解，本书也会逐步完善和更新；另外也会逐步丰富”常用正则“，”应用场景“的内容

## 为什么要写本书

在学习，项目开发，源码阅读中，常有遇到正则表达式。此时，对于大都是读者，借助搜索引擎总能理解或找到合适的正则表达式。有时遇到复杂的正则时，又无从下手，不知其匹配的模式，起初笔者也时常困扰于此

因此，笔者有了系统性重新认识正则的想法，在学习过程中，把查阅资料分析，整理并以电子书的形式记录下来分享给各位读者，期望对大家有所帮助

## 关于正则表达式

一个正则表达式通常被称为一个**模式**（pattern），为用来描述或者匹配一系列匹配某个句法规则的字符串

维基百科关于正则的历史：

> 最初的正则表达式出现于理论计算机科学的自动控制理论和形式化语言理论中。在这些领域中有对计算（自动控制）的模型和对形式化语言描述与分类的研究。
>
> 1940年，沃伦·麦卡洛克与Walter Pitts将神经系统中的神经元描述成小而简单的自动控制元
>
> 1950年代，数学家斯蒂芬·科尔·克莱尼利用称之为“正则集合”的数学符号来描述此模型。肯·汤普逊将此符号系统引入编辑器[QED](https://zh.wikipedia.org/w/index.php?title=QED_%28%E6%96%87%E5%AD%97%E7%B7%A8%E8%BC%AF%E5%99%A8%29\&action=edit\&redlink=1)，随后是[Unix](https://zh.wikipedia.org/wiki/Unix)上的编辑器[ed](https://zh.wikipedia.org/w/index.php?title=Ed_%28%E6%96%87%E5%AD%97%E7%B7%A8%E8%BC%AF%E5%99%A8%29\&action=edit\&redlink=1)，并最终引入[grep](https://zh.wikipedia.org/wiki/Grep)。自此以后，正则表达式被广泛地应用于各种Unix或[类Unix](https://zh.wikipedia.org/wiki/%E7%B1%BBUnix)系统的工具中

## 相关资料

* [正则表达式-runoob](http://www.runoob.com/regexp/regexp-tutorial.html)
* [正则表达式-MDN](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions)
* [正则表达式手册](https://tool.oschina.net/uploads/apidocs/jquery/regexp.html)
* [文章结构参考(TypeScript入门教程)](https://ts.xcatliu.com/introduction)
* [精通正则表达式（正则引擎）](https://www.cnblogs.com/zhuimengdeyuanyuan/archive/2013/02/06/2893240.html)
* [正则表达式和NFA](https://juejin.im/post/5bbab1f5f265da0aa94a2842)
* [正则表达式回溯法原理](https://zhuanlan.zhihu.com/p/27417442)
* [【第1670期】浅谈正则表达式原理](https://mp.weixin.qq.com/s?__biz=MjM5MTA1MjAxMQ==\&mid=2651233058\&idx=2\&sn=eae3df94eac6ae172283342a1f2d5bf0\&chksm=bd4942a68a3ecbb048f6c7f1547aa23f3601aa14ae6e2c1812aef7daa9431898caa548346004\&mpshare=1\&scene=1\&srcid=0718u5nHGvGiJQ5KWg22kesS\&rd2werd=1#wechat_redirect)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nxtech.gitbook.io/regexp/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
