0

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.
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37
Niks
  • 19
  • 5
  • Why not `^[A-Z]{2}$`? `\b` is a word boundary – knittl Oct 04 '21 at 18:15
  • What kind of regex does Power Automate use? Maybe it doesn't support word boundries. Try something simpler like `[A-Z][A-Z]\n` – AaronJ Oct 04 '21 at 18:17
  • Kinttl and AaronJ, I had already tried both the options but for Power Automate doesn't find the location of "AM". It isn't clear to me why it is doing that. – Niks Oct 04 '21 at 18:20
  • @MikeM I am using Power Automate Desktop and it does support Regex. It has option to select "Is regular expression". – Niks Oct 04 '21 at 18:23
  • 1
    Okay, docs [here](https://learn.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/text): "Power Automate Desktop's regular expression engine is [.NET](https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference)." – MikeM Oct 04 '21 at 18:25
  • Thanks Mike! I Checked the docs again and found that following works: [A-Z][A-Z]\r I am still quite new to regex which is a really powerful tool! – Niks Oct 04 '21 at 18:30
  • Are you missing the carriage return character? I.e. use `\r\n`. – MikeM Oct 04 '21 at 18:30

3 Answers3

0

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

Pavel Gomon
  • 213
  • 1
  • 7
0

This is the regular expression that worked for me. Thanks @MikeM and others for quick answers!

\n([A-Z]{2})\r
elcortegano
  • 2,444
  • 11
  • 40
  • 58
Niks
  • 19
  • 5
0

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"
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37