【问题标题】:Regex for a line containing only two capital letters仅包含两个大写字母的行的正则表达式
【发布时间】:2021-11-25 03:35:15
【问题描述】:

我正在寻找 Regex(用于 Power Automate Desktop)来查找仅包含两个大写字母的行。所以在下面的例子中,它应该只找到第 5 行作为正确的选择。

我试过跟随。它适用于regex101 网站,但由于某种原因,它在 Power Automate 中不起作用。有什么建议可以纠正这个正则表达式?

\b[A-Z]{2}\b\n 

示例文本:

HEllo, how are you
This IS test message
is this OK
where are you. I
AM
here.

【问题讨论】:

  • 为什么不^[A-Z]{2}$\b 是单词边界
  • Power Automate 使用哪种正则表达式?也许它不支持单词边界。尝试更简单的方法,例如 [A-Z][A-Z]\n
  • Kinttl 和 AaronJ,我已经尝试了这两个选项,但 Power Automate 找不到“AM”的位置。我不清楚它为什么这样做。
  • @MikeM 我正在​​使用 Power Automate Desktop,它确实支持正则表达式。它可以选择“是正则表达式”。
  • 好的,文档here:“Power Automate Desktop 的正则表达式引擎是 .NET。”

标签: regex power-automate-desktop


【解决方案1】:

这应该可以.*\n([A-Z]{2})\n.*

【讨论】:

    【解决方案2】:

    使用

    (?m)^[A-Z]{2}\r?$
    

    解释

    --------------------------------------------------------------------------------
      (?m)                     set flags for this block (with ^ and $
                               matching start and end of line) (case-
                               sensitive) (with . not matching \n)
                               (matching whitespace and # normally)
    --------------------------------------------------------------------------------
      ^                        the beginning of a "line"
    --------------------------------------------------------------------------------
      [A-Z]{2}                 any character of: 'A' to 'Z' (2 times)
    --------------------------------------------------------------------------------
      \r?                      '\r' (carriage return) (optional (matching
                               the most amount possible))
    --------------------------------------------------------------------------------
      $                        before an optional \n, and the end of a
                               "line"
    

    【讨论】:

      【解决方案3】:

      这是对我有用的正则表达式。感谢@MikeM 和其他人的快速解答!

      \n([A-Z]{2})\r
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-14
        • 2021-08-23
        • 1970-01-01
        • 2021-08-10
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多