How to find text in a string using Power Automate?

In this Power Automate tutorial, we will see how to find text in a string using Power Automate or Microsoft Flow.

We will use 3 methods in Power Automate to find text in a string. These are listed below:

  • substring() with indexOf()
  • slice() with indexOf()
  • split() with replace()

Power Automate find text in string (substring() with indexOf())

Here we will see, how to find text in a string using substring() with indexOf() in Power Automate.

The substring() in Power Automate returns characters from a string beginning at the position provided.

Whereas the indexOf function in Power Automate finds the index or position of a character within a specified string in a case-insensitive manner.

For example, we will take the string as ‘ Product number [#1324]’, then find the 1324′ using substring and indexOf() in Power Automate.

For this, first, we will find the position of # using indexOf(), then with the help of add method, add +1 to the return index. After that, with the substring() we will extract the substring of length 4 from the original string, starting from the result index.

Now let’s see how we can implement using Power Automate.

Step 1: Log in to Power Automate and click +Create in the left navigation -> select Instant Cloud flow.

Fiind text in string in Power automate

Provide the flow name and, select the Manually trigger a flow, click on Create.

Find text in string in Microsoft Power automate

You can see Manually trigger a flow action is added to the flow page.

power automate find text in string

Step 2: Next, click on the select Initialize variable action, then provide the below information.

  • Name: Provide the variable name
  • Type: select the type as the array
  • Value: Provide the value as ‘Product number [#1324]’
Microsoft power automate find text in string

Step 3: Now, we will find the text, click on the +New step -> select Compose action. Then provide the below information:

Inputs: Provide the below expression

substring(variables('Original string'),add(indexOf(variables('Original string'), '#'),1), 4)
MS power automate find text in string

Step 4: Now we will run the flow, click on Test-> select Manually -> click on the Test button. Next, click on the Test. Now you can see the flow run successfully.

find text in a string using Power Automate

Power Automate find text in string (slice() with indexOf())

Here we will see, how to find text in a string using substring() with indexOf() in Power Automate.

The slice method in Power Automate allows you to cut a string by passing it a start index number and an end index number, and it will return the contents of the string between the two values. To get this index number, we will use indexOf().

Whereas, the indexOf function in Power Automate finds the index or position of a character within a specified string in a case-insensitive manner.

For example, we will take the string as ‘ Product number [#1324]’ and then we will find the 1324′ using slice () and indexOf() in Power Automate.

For this first, we will find the position of # using indexOf(), where the position starts from 0. With the help of add method, add +1 to the return index/position.

Next, we will find the position of ‘]’ using indexOf() i.e. the end position. Finally, we will use the slice method to get the substring by using the start and end positions.

Now let’s see how we can implement using Power Automate.

Step 1: In Power Automate, click on the +Create icon in the left navigation menu-> select Instant Cloud flow.

Find text in string in Power automate

Provide the flow name and, select the Manually trigger a flow, click on Create.

Find text in string in Microsoft Power automate

You can see Manually trigger a flow action is added to the flow page.

power automate find text in string

Step 2: Next, click on the select Initialize variable action, then provide the below information.

  • Name: Provide the variable name
  • Type: select the type as an array
  • Value: Provide the value as ‘Product number [#1324]’
Microsoft power automate find text in string

Step 3: Now, we will find the text, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression
slice(variables('Original string'), add(indexOf(variables('Original string'), '#'),1), indexOf(variables('Original string'), ']'))
Microsoft flow  find text in string

Step 4: Now we will run the flow, click on Test-> select Manually -> click on the Test button. Next, click on the Test. Now you can see the flow run successfully.

How to find text in string in Microsoft flow

This is how to find text in a string in Power Automate using slice and index of methods.

Power Automate find text in string (split() with replace())

Here we will see, how to find text in a string using split() with replace() in Power Automate.

The split function in Microsoft Power Automate is used to divide a text string into an array or table of substrings based on a given delimiter. The delimiter is a character or sequence of characters that indicates where to split the original string.

The replace method in Power Automate replaces instances of a given substring in a text string with a new substring.

For example, we will take the string as ‘ Product number [#1324]’, and then we will find the 1324′ using slice () and indexOf() in Power Automate.

First, we split the string at every occurrence of the ‘#’ character and return an array of substrings. The second element of the array can be obtained by passing the index [1]. At last, we will replace the ‘]’ with blank ” using replace ().

Now let’s see how we can implement using Power Automate.

Step 1: In Power Automate, click on the +Create icon in the left navigation menu-> select Instant Cloud flow.

Find text in string in Power automate

Provide the flow name and, select the Manually trigger a flow, click on Create.

Find text in string in Microsoft Power automate

Now, you can see Manually trigger a flow action is added to the flow page.

power automate find text in string

Step 2: Next, click on the select Initialize variable action, then provide the below information.

  • Name: Provide the variable name
  • Type: select the type as an array
  • Value: Provide the value as ‘Product number [#1324]’
Microsoft power automate find text in string

Step 3: Now, we will find the text, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression
split(variables('Original string'), '#')[1]
How to find text in string in MS flow

Step 4: Now, we will find the text, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression
replace(outputs('Compose'),']','')
How to find text in string in Microsoft Power automate

Step 5: Now we will run the flow; click on Test-> select Manually -> click on the Test button. Next, click on the Test. Now you can see the flow run successfully.

How to find text in string in Power automate

This is an example of how to find text in a string in Power Automate using split and replace

Conclusion

In this Power Automate tutorial, we saw how to find the text from a string using Power Automate.

You may also like:

>