【发布时间】:2019-01-21 06:45:20
【问题描述】:
在降价文件中:我希望在 VS Code 中找到 {\display 及其匹配的 }(不支持向后看)。在以下文本中:
Type-2 Context-free Non-deterministic pushdown automaton {\displaystyle A\rightarrow \gamma } A \rightarrow \gamma
Type-3 Regular Finite state automaton {\displaystyle A\rightarrow {\text{a}}} {\displaystyle A\rightarrow {\text{a}}} and {\displaystyle A\rightarrow {\text{a}}B} {\displaystyle A\rightarrow {\text{a}}B}
我希望识别:
{\displaystyle A\rightarrow \gamma }
{\displaystyle A\rightarrow {\text{a}}}
{\displaystyle A\rightarrow {\text{a}}}
{\displaystyle A\rightarrow {\text{a}}B}
{\displaystyle A\rightarrow {\text{a}}B}
我认为正则表达式应该以这个{\ 开头,并且对} 是贪婪的,但不应该在匹配的} 之后包含{\。
我试过(\{\\.*\}),但这并不能识别所有情况。
总结:如果它在下一次出现{\display 之前最后停止} 并且在这两者之间可以有任何字符,则答案将是最一般的。
【问题讨论】:
-
请解释为什么投票赞成关闭?
-
这应该适用于您给定的示例:
{\\display.+?}+(\w})? -
@Deathshadow 谢谢!如果您可以将其转换为答案并在可能的情况下进行解释,那就太好了! :)
标签: regex parsing visual-studio-code regex-greedy