Power Automate Replace Function Explained | Many Examples

Power Automate Replace Function

Almost every text editor has the function to replace text, because it is helpful in many scenarios.

Microsoft flows naturally offer this feature as well. The Power Automate replace function replaces all occurrences of text with its substitute.

In this article the Power Automate replace function is explained in detail and there are many examples of common use cases of the replace function.

Power Automate Replace Function

Power Automate Replace function example

The Power Automate replace function replaces every occurrence of a given text with a given alternative.

Note: The replace function in Power Automate is case-sensitive.

Syntax

replace('<text>', '<oldText>', '<newText>')

Input parameters

  • text (mandatory): The original string that needs to be modified by replacing parts of the string.
  • oldText (mandatory): The searched string that needs to be replaced.
  • newText (mandatory): The substitute string for the old string.

Return value

  • A string that has all occurrences of the searched string replaced with the provided substitute.

Power Automate replace expression examples

replace('abccba','b','a')
=> 'aaccaa'

Power Automate Replace Function Examples

Seeing Power Automate Replace expression examples in common use cases helps to solve your task.

Here is a list of common usage for the Power Automate replace function.

Replace string

This one is simple. Replacing a string in a string.

replace('I am Joe Doe.','Joe','John')
=> I am John Doe.

Replace character in string

This one is simple. Replacing a character in a string.

replace('125','5','3')
=> 123

Replace string in variable

Replacing a string in a variable.

replace(variables('text'),'Joe','John')
=> I am John Doe.
Power Automate Replace string in variable
Power Automate Replace string in variable

Replace multiple characters

To replace multiple characters in a string you can nest replace function calls.

replace(replace(replace('abc','a','1'),'b','2'),'c','3')

Replace multiple strings

To replace multiple strings in a string you can nest replace function calls.

replace(replace('abc','ab','12'),'c','3')
=> 123

Replace single quote

The single quote needs to be decoded to use it in Power Automate replace expression.

Simply replace the single quote by decodeUriComponent(‘%27’).

// triggerBody()['text'] = This is 'funny'.
replace(triggerBody()['text'],decodeUriComponent('%27'),'"')
=> This is "funny".

Replace ampersand

To replace an ampersand just do the following.

replace('me&you','&',' and ')
=> me and you

Replace backslash

To replace a backslash just do the following.

replace('aa\bb','\',' ')
=> aa bb

Remove brackets

To remove brackets replace them with nothing.

replace(replace('(Joe)','(',''),')','')
=> Joe

Replace line break with br

To address line break in a Power Automate replace expression you need to decode them like this: decodeUriComponent(‘%0A’)

//triggerBody()['text'] =
//a
//b
replace(triggerBody()['text'],decodeUriComponent('%0A'),'<br/>')
=> a<br/>b

Replace comma with new line

To address line break in a Power Automate replace expression you need to decode them like this: decodeUriComponent(‘%0A’)

replace('apple,mango',',',decodeUriComponent('%0A'))
=> 
apple
mango

Replace comma with semicolon

Replacing a comma with a semicolon is straight forward.

replace('apple,mango','/',';')
=> apple;mango

Replace doublequote with single quote

The single quote needs to be decoded to use it in Power Automate replace expression.

Simply replace the single quote by decodeUriComponent(‘%27’).

replace('This is "funny".','"',decodeUriComponent('%27'))
=> This is 'funny'.

Replace forward slash

To replace a forward slash just do the following.

replace('aa/bb','/',' ')
=> aa bb

Replace newline with space

To address line break in a Power Automate replace expression you need to decode them like this: decodeUriComponent(‘%0A’)

// triggerBody()['text'] =
//a
//b
//c
replace(triggerBody()['text'],decodeUriComponent('%0A'),' ')
=> a b c

1 thought on “Power Automate Replace Function Explained | Many Examples”

Leave a Comment

Your email address will not be published. Required fields are marked *