惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - Zhenway

Azure SignalR支持replication啦 Azure SignalR总览 定制json序列化 docfx组件介绍--YamlSerialization docfx daylybuild docfx开源啦 docfx组件介绍--MarkdownLite docfx预热中 合并批量请求 一个简单的Linq to TreeNode 在finally中调用一个需要await的方法 当泛型方法推断,扩展方法遇到泛型类型in/out时。。。 4.5你太黑了,不带这么玩TypeForwardedTo的 一个非常简单的反射加速方案 加载时预防并发执行 又发现一个msdn的坑 又发现个.net framework的坑 sql server死锁神器 踩到一个Emit的坑,留个纪念
今天折腾这么一个正则
Zhenway · 2016-02-16 · via 博客园 - Zhenway

  今天一天折腾了这么一个正则

new Regex(@"^!?\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\s*\(\s*<?((?:[^()]|\((?<DEPTH>)|\)(?<-DEPTH>))+?(?(DEPTH)(?!)))>?(?:\s+(['""])([\s\S]*?)\3)?\s*\)");

  话说这个正则是干什么用的,故事是这样的:

  很久很久以前

  我在markdownlite里面抄了个marked里面的正则

  一切都很好。

  突然,

  有用户报我们的markdown不对,

  什么情况?

  一问是link的处理有问题。

  是什么奇葩link那?

  打开一看,

  映入眼帘的是:

  marked里面的正则会处理成:

<a href="foo(bar">hello</a>bar).md)

  确实bar后面都跟)了链接就到处为止了,

  看起来是用户内容有问题啊!

  再跑到github里面一试,

  傻眼了:

<a href="foo(bar).md">hello</a>

  吐血中。。。

  再试了很多case后,

  发现github只要在link target里面的的()是成对出现的就能work。

  于是就有了今天这个正则。

  这个复杂的正则需要这么去理解:

^                                           start of string
!?                                          '!' 0~1
\[                                          '['
((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)    group 1: text
\]                                          ']'
\s*                                         white spaces
\(                                          '('
\s*                                         white spaces
<?                                          '<' 0~1
(                                           start group 2: link
    (?:                                     start non-capturing group
        [^()]                               any chararacter but '(' or ')'
    |                                       or
        \((?<DEPTH>)                        '(' with depth++
    |                                       or
        \)(?<-DEPTH>)                       ')' with depth--
    )                                       end non-capturing group
    +?                                      lazy 1~
    (?(DEPTH)(?!))                          require depth = 0
)                                           end group 2: link
>?                                          '>' 0~1
(?:                                         start non-capturing group
    \s+                                     white spaces
    (['"])                                  group 3: quote ' or "
    ([\s\S]*?)                              group 4: title
    \3                                      ref group 3
)?                                          end non-capturing group 0~1
\s*                                         white spaces
\)                                          ')'