【问题标题】:RegEx for matching square bracketed words with no parenthesis followingRegEx 用于匹配方括号中的单词,后面没有括号
【发布时间】:2019-05-07 20:19:17
【问题描述】:

我想用一个简单的预处理选项来扩展 Markdown 的语法。

当文本在方括号中包含一些单词,但后面没有括号时:

Example text with [some reference] to show.

我想扩展它,使它成为一个自引用链接:

Example text with [some reference](some-reference.html) to show.

创建结果本身是我可以自己做的事情,但我不知道,我如何才能只匹配这些表达式:

A word [and more] in the text.                    // this matches
A word [and more](stackoverflow.com) in the text. // this doesn't

【问题讨论】:

  • @shadoe2020 似乎都按我的预期工作,非常感谢!
  • 您介意我将其作为答案发布并且您可以选择它,因为它对您有用吗?
  • 我当然不知道,谢谢!

标签: javascript regex markdown regex-greedy


【解决方案1】:

\[(.*?)\] 第一个,第二个\]\((.*?)\)

【讨论】:

    【解决方案2】:

    像这样的

    \[([^\[\]]*)\](?!\([^()]*\))

    https://regex101.com/r/64unOk/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      相关资源
      最近更新 更多