仅包含两个大写字母的一行的正则表达式



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

我试着跟随。它可以在regex101网站上工作,但由于某种原因,它不能在Power automation中工作。有什么建议来纠正这个正则表达式吗?

b[A-Z]{2}bn 

示例文本:

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

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

使用

(?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"

这是适合我的正则表达式。感谢@MikeM和其他人的快速回答!

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

最新更新