cancel
Showing results for 
Search instead for 
Did you mean: 

Support for regex - either in conditions or as an action with capture groups exposed

It would be really good to have support for regular expressions.

 

This could be surfaced in the UI ideally in both conditions and actions.

 

A conditional regex would just test whether a string matched against a regex.

An action regex would expose capture groups.

Status: Under Review

This is a great suggestion - we are trying to identify a way to safely run regex in Flow.

Comments
Paulie78
Super User III

Hi Everyone,

I have written up a way of performing regular expressions in Power Automate for free, without the use of any third party connectors:

How to use Regex in Power Automate 

Be interested to hear how you get on with the solution.

Paul

DM2
Frequent Visitor

Hi @Paulie78.  Wow, that's a neat addition to the repertoire.  I'd never have thought of that one! 

 

Neat blog you have too.  That's going on my favourites!

 

I have a suspicion that an azure function is probably the way to go for the generic case but this is simple and really neat when you know you have Excel around.

 

And as you so rightly say (in your blog) we need to keep upvoting this and get MS to implement it - or if not at least tell us why it's so difficult!

 

Thanks again - nice one.

roshanma
Frequent Visitor

@Paulie78 

Never thought about that.

Thanks this is very useful.

 

Yes. @DM2  we must keep this thread,

cvillegas
Regular Visitor

@Paulie78 great suggestion, would still like for MSFT to add this to the product suite though without workarounds.

teqs
Kudo Collector

I check Flow ideas about every 6 months. And it's every time totally shocking for me that a basic and so very, very important (and needed) feature like RegEx support is not implemented yet. And not even "in implementation". It's from 2017, top voted most of the time.

It would make so many things for Searching, Filtering, Replacing (!) so much easierRegeEx is a simple and very, very powerful tool. Much better as implemented text search/split, etc. 

 

What we need?

1. Regex should be possible for conditions and also to search in a string for matching groups and get the matches as output

2. And also of course for text replace, same like in SED.

Having RegEx available for conditions, string search and replaces, will decrease the need of a lot of compose-chains and expression-chains.

BO55VXR
Advocate II

Well, its been FOUR years now and I am so fed up with it not being available I've now created a Azure Function App (with HTTP trigger) to do this... If anyone else wants to do this, here's my code.

 

 

    public static class RegEx
    {
        [FunctionName("RegEx")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "RegEx")] HttpRequest req,
            ILogger log)
        {
            // Get the request details
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            RegExRequest request = JsonConvert.DeserializeObject<RegExRequest>(requestBody);

            JObject response = new JObject();

            MatchCollection mc = Regex.Matches(request.Input, request.Pattern);
            if (mc.Count > 0)
            {
                JArray matches = new JArray();
                response["success"] = true;
                foreach (Match m in mc)
                {
                    JObject matchGroups = new JObject();
                    RegExResponseMatch rm = new RegExResponseMatch();
                    for (int g = 1; g < m.Groups.Count; g++)    // Group 0 is the matched string so we ignore it
                    {
                        matchGroups[m.Groups[g].Name] = m.Groups[g].Value;
                    }
                    matches.Add(matchGroups);
                }
                response["matches"] = matches;
            }
            else
            {
                response["success"] = false;
                response["matches"] = new JArray();
            }

            return new OkObjectResult(response);
        }
    }

    public class RegExRequest
    {
        public string Input { get; set; }
        public string Pattern { get; set; }
    }

    public class RegExResponse
    {
        public bool Success { get; set; }
        public ICollection<RegExResponseMatch> Matches { get; set; }
        public RegExResponse()
        {
            Matches = new List<RegExResponseMatch>();
        }
    }

    public class RegExResponseMatch
    {
        public ICollection<KeyValuePair<string, string>> Groups;
        public RegExResponseMatch()
        {
            Groups = new List<KeyValuePair<string, string>>();
        }

    }

 

Using Postman, this is the request / response

BO55VXR_0-1623405274510.png

 

 

teqs
Kudo Collector

 @BO55VXR 
Thanks a lot, this is great!
Even I have programming skills and know Power Automate, I am totally new to azure. Would be great if you can spend some small advices.
- Do we have to make a new subscription to host a function on azure or is it include to have a few functions hosted in office 365 basic plans ("Microsoft 365 Business Standard")? (Or at least in a "Microsoft 365 Business Premium" subscription)
- If not included, do you pay per function call or per cpu time (or whatever)?

- Do you know a easy tutorials how to make your code working as a function in azure which can be called from outside?