Power Automate Regular Expressions
As my work with Power Automate becomes more frequent these days, the need for custom regular expressions grows.
Here's 2 of favorite regular expressions that may save you some time.
1. GREP FOR ITEM
Sometimes we need to grep for specific strings from previous Power Automate outputs.
Let's say you are parsing JSON from a API response, however you would like to grep for the last few characters. one way to do this is by converting the API response to raw text:
You can do this by adding the "HTML to text" action in your Flow.

We can now use the raw text output for our data manipulation.
Create Compose step and click on the "Expression" tab.


Populate the value with the following and click ok: last(split(body('api_output'),'/item/'))

The above will show you all the characters after /item/
I am using my grep for a Jenkins API I am calling via Power Automate Custom Connector.
I had the need to get the Item number:

2. Remove last character & Remove Spaces
As mentioned above, I needed the Jenkins Item number to call another API to get the Jenkins Build Number using the Item Number. The issue here is that our string above has a slash at the end & a space. Here is my second fav regular expression you can use to "trim" and remove the trailing characters.
Create another "Compose" action after the grep item Compose we created above.
click on the "Expression" tab


Populate the value with the following and click ok: substring(outputs('api_output'),0,sub(length(outputs('api_output')),1))

The output of the above will be your string you grep'd for minus the trailing slash and spaces.

Hope this helps someone !