Home > Enterprise >  Regex for a line containing only two capital letters
Regex for a line containing only two capital letters

Time:10-05

I am looking for Regex (to be used in Power Automate Desktop) for finding a line containing only two capital letters. So in below example, it should find only line 5 as the correct choice.

I tried following. It works in regex101 website but for some reason it doesn't work in Power Automate. Any suggestions to correct this regex?

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

Sample text:

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

CodePudding user response:

This should work .*\n([A-Z]{2})\n.*

CodePudding user response:

Here is what finally worked for me. Thanks @MikeM and others for quick answers!

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

CodePudding user response:

Use

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

EXPLANATION

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