[英]What does the look ahead in Regex do?
I need help deciphering Regex 我需要解密正则表达式的帮助
(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1
This came from showdown.js 这来自showdown.js
(\*\*|__) match ** or __
(?=\S) -> look ahead for *one* non-space character? what for?
([^\r]*?\S[*_]*) -> zero or more non-carriage-returns, why newlines \n allowed?, one non-space, zero or more * or _ characters
\1 ends with 1st capture: ** or __
I mainly don't get the 2nd & 3rd lines 我主要不知道第二和第三行
I'll take a stab at the second part (keep in mind I guess based on the knowledge that this is a JS Markdown parser): 我将在第二部分进行介绍(请记住,我想这是基于JS Markdown解析器的知识):
The lookahead assertion (?=\\S)
is probably there in case someone wants to write two asterisks ** or two underscores __ without wanting to bold the text that comes after it that is separated by a space (see what I did there?). 如果有人要写两个星号**或两个下划线__而不想要加粗用空格隔开的后面的文本,那么可能会出现先行断言
(?=\\S)
(看我在那儿做了什么?) 。
** This text will not be bold. **
**This text will be bold.**
** This text will not be bold.
**此文本将不会为粗体。 **
**
This text will be bold.该文本将为粗体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.