cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lipsitz
Advocate I
Advocate I

Caret as beginning of line in REGEX - Identifying empty lines

I want to remove some empty lines in a file.

In REGEX the following always works to find an empty line

 

 

 

^\r\n

 

 

 

Since the caret indicates the beginning of a line, as documented by Microsoft here

https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-refere...

But PAD totally ignores it. why? and what would be a good workaround?

4 REPLIES 4
fraenK
Super User
Super User

Your regex is looking for line breaks at the beginning of a line. You can use trim for this: https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/text#trim

Right, that is what I want to get rid of, lines that only contain line breaks.

The same REGEX formula is working in Dreamweaver and Notepad++, why is is not working in PAD?

Its not just for empty lines, for which trim might have been a good workaround, it does not work at all.

Henrik_M
Super User
Super User

Might be a silly solution, but this technique removes empty lines:

 

Henrik_M_0-1619177119756.png

 

burque505
Helper V
Helper V

At the risk of confusing the issue, here's another empty-line removal flow.

newline_text.PNG

flow.PNG

look_ma_no_linebreaks.PNG

 

That said, I can see that in certain situations this might not work for you. This should match an empty line but process a carriage return if present:

^\n$

where the '$' will (almost always?) be superfluous and you'd get the same result with

^\n

I'm trying to think of scenario where you'd have a carriage return and linefeed at the beginning of line, but also something else before the end of the line- stumped. If that's the case, would you mind posting an example of what you want to find with your regex?

Regards,

burque505

Helpful resources

Announcements
Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Users online (2,473)