Skip to main content

Notifications

Community site session details

Community site session details

Session Id : AH6xq5ZGx6C17asCvHL1ja
Power Automate - Power Automate Desktop
Answered

How to remove the new line formed when parsing a text

Like (0) ShareShare
ReportReport
Posted on 28 Aug 2023 10:26:46 by 49

Hello,

 

I'm new to PAD and Regex, and I tried extracting text from a pdf then parsing it so I can get a text of:

 

Article X Section Y

 

I used the regex (?i)article\s?\n?\s\d\d?\s?\n?((?i)section\s?\n?\d\d?)? just in case the full text is separated with a line in the pdf, also in case the X and Y contains more than one digit.

 

The problem is, it seems that the text extracted is separated with a line, so it looks like this:

 

Article

X Section Y

 

I tried replacing the regex \n in the extracted text with %""% to delete the new line but it doesn't seem to work.
Can anyone help?

Thanks in advance.

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 30 Aug 2023 at 04:31:11
    Re: How to remove the new line formed when parsing a text

    You can use Replace text with regex to replace specific empty strings with a whitespace.

    Using (?<=[A-z])(?=\d) will replace the empty string after a word and followed by a digit. You can replace it with %" "% and that will result in a whitespace.

    You can then also reverse that to also add a whitespace after a digit and followed by a word in another Replace text action using (?<=\d)(?=[A-z]) as the regex pattern.

     

    If you combine both, you'll get your desired result.

    -------------------------------------------------------------------------
    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.

  • devinpal Profile Picture
    49 on 30 Aug 2023 at 01:56:37
    Re: How to remove the new line formed when parsing a text

    How about inserting a space between two characters? Is it possible?
    For example I want to make the text "ArticleXsectionY" into "Article X section Y"

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 29 Aug 2023 at 10:35:56
    Re: How to remove the new line formed when parsing a text

    A carriage return is a special character that is similar to newline. See here for more info: https://en.m.wikipedia.org/wiki/Carriage_return

     

    \r matches a carriage return and \n matches a newline. The question marks indicate that both are optional, so that it works if any or both of them is present.

     

    If you want to replace it with a whitespace, use %" "% as the value to replace it with (a whitespace between quotes) or \s with escape sequences enabled.

    -------------------------------------------------------------------------

    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.

     

  • devinpal Profile Picture
    49 on 29 Aug 2023 at 10:29:22
    Re: How to remove the new line formed when parsing a text

    It worked! Thank you!

    If you don't mind, can you tell me what is carriage return and what does \r?\n? do?

    Also, is there a way to insert a space in the output text because now I get "Article9 section 1"

  • Verified answer
    Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 29 Aug 2023 at 10:23:02
    Re: How to remove the new line formed when parsing a text

    You may have a carriage return there. Try replacing \r?\n? instead of just the \n.

    -------------------------------------------------------------------------

    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.

     

  • devinpal Profile Picture
    49 on 29 Aug 2023 at 10:07:43
    Re: How to remove the new line formed when parsing a text

    Thank you very much for the replies.

    I tried simplifying the flow (I removed the second parse) and used the replace \n.

     

    devinpal_3-1693304024738.png

     

    devinpal_2-1693303745265.png

     

    But when I tried displaying it as a message in PAD, the new line is still there.

     

    devinpal_0-1693303484574.png

     

    I tried exporting the list as a .txt file and the new line's also there.

     

    devinpal_1-1693303588672.png

     

    Am I still doing something wrong? What information should I provide further?
    Thank you in advance.

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 29 Aug 2023 at 08:47:25
    Re: How to remove the new line formed when parsing a text

    Why exactly are you using Parse text inside the loop if you're already iterating through a list of matches that were retrieved via Parse text earlier?

    The way I see it, you should simply do this:

    • Parse text - to get the matches from the PDF text
    • Create new list
    • For each CurrentItem in Matches
      • Replace text in CurrentItem
      • Add item to list to add the replaced text to the list
    • End

    And then at the end make sure you're using the %ArticleList% variable and not %Matches% when you want to use the text after replacing newlines.

    -------------------------------------------------------------------------
    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.

  • devinpal Profile Picture
    49 on 29 Aug 2023 at 07:12:14
    Re: How to remove the new line formed when parsing a text

    Yes, I made a loop to put all the texts in a list.

    devinpal_0-1693293065415.png

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 29 Aug 2023 at 06:42:43
    Re: How to remove the new line formed when parsing a text

    Okay. And then you somehow put it into a list?

  • devinpal Profile Picture
    49 on 29 Aug 2023 at 06:34:24
    Re: How to remove the new line formed when parsing a text

    Sorry for the trouble, this is what I did to remove the new line.

    devinpal_0-1693290453499.png


    and this is what I did to get the text.

    devinpal_1-1693290768879.png

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started