How to extract characters before, after, or between specific text.(Power Automate Desktop)

Japanese version.

This section shows how to extract the left or right and between characters from a specified character.

Extract left or right from the specified character.

Overall flow

Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

SET Text TO $'''abcde'''
SET Char TO $'''c'''
Text.ParseText.ParseForFirstOccurrence Text: Text TextToFind: Char StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position
IF Position > 0 THEN
    Text.GetSubtext.GetSubtextFromStartTo Text: Text NumberOfChars: Position Subtext=> Subtext_Left
    Text.GetSubtext.GetSubtextFrom Text: Text CharacterPosition: Position + 1 Subtext=> Subtext_Right
END

Steps

First, prepare variables.

VariableName(Example)
Source text.%Text%
Target character.%Char%

Put in place a "Parse text".

ParameterValue
Text to be parse%Text%
Text to be find%Char%
Is regular expressionOFF
Start parsing at position0
First occurrence onlyON

Put in place an "If" to check for error.

ParameterValue
First operand%Position%
OperatorGreater than(>)
Second operand0

Put in place "Get subtext" in "If".

If you want to extract the text to the left of %Char%, set as follows.

ParameterValue
Original text%Text%
Start IndexStart of text
LengthNumber of chars
Number of chars%Position%

If you want to extract the text to the right of %Char%, set as follows.

ParameterValue
Original text%Text%
Start IndexCharacter position
Character position%Position + 1%
LengthEnd of text

When the Flow to run, the extracted text is set to the variable produced in "Get subtext".

Extract between specified characters.

Overall flow

Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

SET Text TO $'''abcdeABCDE'''
SET FromChar TO $'''c'''
SET ToChar TO $'''C'''
Text.ParseText.ParseForFirstOccurrence Text: Text TextToFind: FromChar StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position_Left
Text.ParseText.ParseForFirstOccurrence Text: Text TextToFind: ToChar StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position_Right
IF (Position_Left > 0 AND Position_Right > 0) = True THEN
    Text.GetSubtext.GetSubtext Text: Text CharacterPosition: Position_Left + 1 NumberOfChars: Position_Right - Position_Left - 1 Subtext=> Subtext
END

Steps

First, prepare variables.

VariableName(Example)
Source text.%Text%
Target letter on the left.%FromChar%
Target letter on the right.%ToChar%

Next, put in place two "Parse text".

ParameterValue
Text to be parse%Text%
Text to be find%FromChar%
Is regular expressionOFF
Start parsing at position0
First occurrence onlyON
Variables produced%Position_Left%
ParameterValue
Text to be parse%Text%
Text to be find%ToChar%
Is regular expressionOFF
Start parsing at position0
First occurrence onlyON
Variables produced%Position_Right%

Put in place an "If" to check for error.

ParameterValue
First operand%Position_Left> 0 AND Position_Right > 0%
OperatorEqual to (=)
Second operand%True%

Put in place "Get subtext" in "If".

ParameterValue
Original text%Text%
Start IndexCharacter position
Character position%Position_Left+ 1%
LengthNumber of chars
Number of chars%Position_Right - Position_Left - 1%

When the Flow to run, the extracted text is set to the variable produced in "Get subtext".

For those who want to learn Power Automate Desktop effectively


The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.

Table of Contents.

Update History.

Links

Tips(Power Automate Desktop)