Skip to main content
Community site session details

Community site session details

Session Id : CBFy4UMXMg6k8mF8kyXdCX
Power Automate - Power Automate Desktop
Answered

Split text based on char type

Like (0) ShareShare
ReportReport
Posted on 14 Jul 2023 09:45:31 by 20

Hello All,

 

I want to split this text:

 

from this:

BRAVIA10458056700005349ATM John Doe 0580901 0.00 155,000.00 51,700,715.00

BRAVIA10458056700005349ATM John Doe 8980901 0.00 155,000.00 51,700,715.00

 

Into this:

List 1List 2List 3List 4
05809010.00155,000.0051,700,715.00
89809010.00155,000.0051,700,715.00

 

Please kindly suggest how can I achieve this? the only pattern is they start with 7 digits numbers.

 

Thank you before, any clue is appreciated.

  • chillerbox Profile Picture
    20 on 18 Jul 2023 at 04:50:03
    Re: Split text based on char type

    Hi Agnius,

     

    Again, thank you for the reply. Right now, I'm using crop text to match the text before parsed text, but I will test your solution to see which is faster.

     

    chillerbox_0-1689655779956.png

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on 18 Jul 2023 at 04:42:06
    Re: Split text based on char type

    You could do that by modifying the regular expression pattern to .+\d{7}\s\d.+

    Doing so will essentially include everything that comes before the 7-digit number all the way since the previous newline.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • chillerbox Profile Picture
    20 on 18 Jul 2023 at 04:25:13
    Re: Split text based on char type

    Hi Agnius,

     

    Thank you for your response, it worked like wonder.  Do you happen to know how to get the text before the parsed one?

    "BRAVIA10458056700005349ATM John Doe" -> this text does not have any pattern and the length is dynamic.

     

     

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on 14 Jul 2023 at 10:48:10
    Re: Split text based on char type

    You need to use Parse text with regular expressions enabled and use the following pattern to extract the relevant values first: \d{7}\s\d.+

    This will result in a list of matches with the following items:

    • 0580901 0.00 155,000.00 51,700,715.00
    • 8980901 0.00 155,000.00 51,700,715.00

    You can then loop through the list and use Split text on each item to split it by space. And then you can add it to your new lists.

     

    Here's a sample flow:

     

    Agnius_0-1689331364610.png

     

    And here's a snippet that you can copy and paste to your PAD designer to have those actions generated automatically for you:

    SET Text TO $'''BRAVIA10458056700005349ATM John Doe 0580901 0.00 155,000.00 51,700,715.00
    BRAVIA10458056700005349ATM John Doe 8980901 0.00 155,000.00 51,700,715.00'''
    Text.ParseText.RegexParse Text: Text TextToFind: $'''\\d{7}\\s\\d.+''' StartingPosition: 0 IgnoreCase: False Matches=> Matches
    Variables.CreateNewDatatable InputTable: { ^['Column1', 'Column2', 'Column3', 'Column4'], [$'''''', $'''''', $'''''', $''''''] } DataTable=> DataTable
    Variables.DeleteRowFromDataTable DataTable: DataTable RowIndex: 0
    LOOP FOREACH CurrentItem IN Matches
     Text.SplitText.Split Text: CurrentItem StandardDelimiter: Text.StandardDelimiter.Space DelimiterTimes: 1 Result=> TextList
     Variables.AddRowToDataTable.AppendRowToDataTable DataTable: DataTable RowToAdd: TextList
    END

     

    Note: I use a data table there, because that's a personal preference. If you need those values in lists, you can also create 4 separate lists and then add the values separately to each of them inside the loop. You can reference the values of %TextList% after using Split text by using an index as follows:

    Agnius_2-1689331631029.png

    Here's a snippet for this approach, too:

    SET Text TO $'''BRAVIA10458056700005349ATM John Doe 0580901 0.00 155,000.00 51,700,715.00
    BRAVIA10458056700005349ATM John Doe 8980901 0.00 155,000.00 51,700,715.00'''
    Text.ParseText.RegexParse Text: Text TextToFind: $'''\\d{7}\\s\\d.+''' StartingPosition: 0 IgnoreCase: False Matches=> Matches
    Variables.CreateNewList List=> List1
    Variables.CreateNewList List=> List2
    Variables.CreateNewList List=> List3
    Variables.CreateNewList List=> List4
    LOOP FOREACH CurrentItem IN Matches
     Text.SplitText.Split Text: CurrentItem StandardDelimiter: Text.StandardDelimiter.Space DelimiterTimes: 1 Result=> TextList
     Variables.AddItemToList Item: TextList[0] List: List1
     Variables.AddItemToList Item: TextList[1] List: List2
     Variables.AddItemToList Item: TextList[2] List: List3
     Variables.AddItemToList Item: TextList[3] List: List4
    END

     

    I personally prefer working with data tables, though, as it is cleaner and usually requires less actions.

     

    Alternatively, you can create the data table originally (my first sample) and add 4x Retrieve data table column into list actions after the loop to save the columns as lists like this:

    Agnius_1-1689331546295.png

    Here's the snippet for the 4 extra actions:

    Variables.RetrieveDataTableColumnIntoList DataTable: DataTable ColumnNameOrIndex: 0 ColumnAsList=> List1
    Variables.RetrieveDataTableColumnIntoList DataTable: DataTable ColumnNameOrIndex: 1 ColumnAsList=> List2
    Variables.RetrieveDataTableColumnIntoList DataTable: DataTable ColumnNameOrIndex: 2 ColumnAsList=> List3
    Variables.RetrieveDataTableColumnIntoList DataTable: DataTable ColumnNameOrIndex: 3 ColumnAsList=> List4

     

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution.
    If you like my response, please give it a Thumbs Up.

    If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2

Loading started
Loading complete