web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Enabling Multiline Reg...
Power Automate
Answered

Enabling Multiline Regex with ^ and $ Anchors in Power Automate Desktop

(0) ShareShare
ReportReport
Posted on by 78

I was wondering how to make my regexes, which include the anchors ^ and $, work in Power Automate Desktop. When I input them directly into PAD, they do not work. I tested them on http://regexstorm.net/tester and noticed they only work if I enable the multiline flag. So, how can I do this in PAD?

  • CU31080729-3 Profile Picture
    502 Moderator on at

    Hi,

    can you explain your scenario or can you provide your input text and what exactly output text you need , its better to understand.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Chetan Ninghot

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Ronyn77 

     

    Can you please offer additional context regarding your objectives here? It would be helpful to see examples, a screenshot of your flow, and the regex pattern you are using?

     

  • Verified answer
    Ronyn77 Profile Picture
    78 on at

    The regular expressions I am using can be quite complex. However, to give a clear example, consider matching only numbers that consist of exactly three digits and are positioned at the beginning of a line.

    The regex should be something like `^\d{3}`... This will not work if I do not enable the multiline flag on [http://regexstorm.net/tester](http://regexstorm.net/tester)...which I do not know how to do in PAD. Meanwhile, I found a workaround, which is to use `\n` in front of `\d{3}`, so by using `\n\d{3}`, I can achieve the same result... However, if there is another way, you are more than welcome to show me how.

     

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    PAD does not support the "multiline" feature. If you use the ^ anchor, it only works with the beginning of the entire string, and not a line. So, your best bet is to use positive lookaheads and lookbehinds with \n to match stuff that is either at the beginning or the end of a line.

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Ronyn77 

     

    As @Agnius  said, PAD won't support multiline option in Text actions. But you can get the same via writing a .net script using run .net script action.

     

    See below

     

    let's say this is the text

    Nived_Nambiar_0-1710665120734.png

     

    Now use Run .net script like below

    Nived_Nambiar_1-1710665151444.png

     

    Set input and output arguments like below

    Nived_Nambiar_2-1710665173157.png

     

    Code used

    Nived_Nambiar_3-1710665186829.png

     

    Code 

     

    outputstr= System.Text.RegularExpressions.Regex.Match(inputstr,"^.*\s+RPA$",System.Text.RegularExpressions.RegexOptions.Multiline).Value.ToString

     

     

    Here i am trying to capture the last line This is RPA sentence, But in the vb.net code i have set up the multiline option using System.Text.RegularExpressions.RegexOptions.Multiline

     

    See the result after running the flow

    Nived_Nambiar_4-1710665272614.png

     

     

    Hope it helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • Ronyn77 Profile Picture
    78 on at

    I tried following your suggestion. Initially, it seemed to work, but ultimately it did not.

    Please go on .NET Regex Tester - Regex Storm

    and paste this as input:

    Brazil 8GA
    Germany 002
    Palma de maiorka 80C
    Rio de Janero 002

     

    I aim to match the last 3 digits of each line, so using regex101: build, test, and debug regex

    with(?:.{3})$, it works.

    However, it does not work if I switch to .NET regex and change the $ to (?=\n) in Regex Storm. Moreover, here I need to modify the .{3} to .{4}, which I cannot understand why.

     

  • Ronyn77 Profile Picture
    78 on at

    I found it. I should add the \r, so using (.{3})\r\n it works...

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Ronyn77 

     

    did you tried the approach which i have shared ?

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • Ronyn77 Profile Picture
    78 on at

    Hello @Nived_Nambiar,

    Your solution seemed more complicated at first glance. I am too busy at work at the moment... when i will have a little more time, i will check.

  • Ronyn77 Profile Picture
    78 on at

    I tried your solution, but I'm not sure if I implemented it correctly.

    I want to execute the following regex, which I finally found works for more cases: `(?:.+)(?= )|(?:.{3})((?=\r\n)|$(?!\r\n))`. Of course, it doesn't work because of the `$`.

    Ronyn77_0-1711012837615.png

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 321 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 244

#3
Henil Profile Picture

Henil 102

Last 30 days Overall leaderboard