regex - 在 Visual Studio Code 中搜索时匹配括号内的字符串

标签 regex visual-studio-code

我正在使用 \((?!\s)([^()]+)(?<!\s)\)要匹配的正则表达式 (string)但不是 ( string )也不是 ()在 Sublime Text 中搜索时。

由于 VS Code 不支持正则表达式中的反向引用,我想知道如何修改原始正则表达式以在此编辑器中获得相同的结果。

有任何想法吗?

最佳答案

您可以使用

\(([^()\s](?:[^()]*[^()\s])?)\)

regex demo

详情
  • \( - (字符
  • ([^()\s](?:[^()]*[^()\s])?) - 第 1 组:
  • [^()\s] - 除 ( 以外的字符, )和一个空格
  • (?:[^()]*[^()\s])? - 一个可选序列(以便也匹配像 (a) 这样的字符串,括号内有 1 个字符)
  • [^()]* - 除 ( 之外的 0+ 个字符和 )
  • [^()\s] - 除 ( 以外的字符, )和一个空格
  • \) - 一个 )字符。
  • 关于regex - 在 Visual Studio Code 中搜索时匹配括号内的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52003189/

    相关文章:

    visual-studio-code - VS代码: Individual zoom levels for each open VSCode window (Multiple monitor setup with vertical monitor)

    node.js - 工作区设置权限被拒绝

    firebase - 带有 VScode 的 Firebase 智能感知

    python - 如何在python中提取txt文件中的数字

    正则表达式 : How to remove all whitespaces around certain character?

    regex - 如何仅使用 grep 将特定数字范围与正则表达式匹配

    git - vscode - 将一个分支 merge 到另一个分支

    java - 使用逗号分隔值但保留括号内使用的逗号的正则表达式模式

    python - 正则表达式无法逃脱问号?

    visual-studio-code - 如何使用 Microsoft VSCode 隐藏/取消隐藏评论?