How to extract characters before, after, or between specific text.(Power Automate Desktop)
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.
Variable | Name(Example) |
---|---|
Source text. | %Text% |
Target character. | %Char% |
Put in place a "Parse text".
Parameter | Value |
---|---|
Text to be parse | %Text% |
Text to be find | %Char% |
Is regular expression | OFF |
Start parsing at position | 0 |
First occurrence only | ON |
Put in place an "If" to check for error.
Parameter | Value |
---|---|
First operand | %Position% |
Operator | Greater than(>) |
Second operand | 0 |
Put in place "Get subtext" in "If".
If you want to extract the text to the left of %Char%, set as follows.
Parameter | Value |
---|---|
Original text | %Text% |
Start Index | Start of text |
Length | Number of chars |
Number of chars | %Position% |
If you want to extract the text to the right of %Char%, set as follows.
Parameter | Value |
---|---|
Original text | %Text% |
Start Index | Character position |
Character position | %Position + 1% |
Length | End 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.
Variable | Name(Example) |
---|---|
Source text. | %Text% |
Target letter on the left. | %FromChar% |
Target letter on the right. | %ToChar% |
Next, put in place two "Parse text".
Parameter | Value |
---|---|
Text to be parse | %Text% |
Text to be find | %FromChar% |
Is regular expression | OFF |
Start parsing at position | 0 |
First occurrence only | ON |
Variables produced | %Position_Left% |
Parameter | Value |
---|---|
Text to be parse | %Text% |
Text to be find | %ToChar% |
Is regular expression | OFF |
Start parsing at position | 0 |
First occurrence only | ON |
Variables produced | %Position_Right% |
Put in place an "If" to check for error.
Parameter | Value |
---|---|
First operand | %Position_Left> 0 AND Position_Right > 0% |
Operator | Equal to (=) |
Second operand | %True% |
Put in place "Get subtext" in "If".
Parameter | Value |
---|---|
Original text | %Text% |
Start Index | Character position |
Character position | %Position_Left+ 1% |
Length | Number 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.
Discussion
New Comments
No comments yet. Be the first one!