Regex for matching linefeed with next character ignored - regex

I am trying to select linefeed and remove them in a comma separated file via REGEX search in notepad++, the criteria for matching linefeed is that it should not followed the character "I" in the next line.
Example:-
Output should be:-

Tip: don't use images as we can't copy past them
replace
\r\n(?!|)
with nothing
Note that I assume your are using windows linebreaks \r\n

Related

Notepad++ N text lines separated by blank lines?

I searched a bit, but didn't find a solution for this specific situation. I need to combine groups of non-blank lines into single lines, while preserving the blank lines. For example, the input:
Hi, My name is
Max
What are you
doing
Right now?
Hi
Hello
World
should be output as:
Hi, My name is Max
What are you doing Right now?
Hi
Hello World
Thanks in advance to all who respond.
You could try replacing
(?<![\n\r])[\n\r](?![\n\r])
With a space, as demonstrated here
Explanation -
(?<![\n\r]) is a negative look-behind which tells the regex that anything to be matched must not be preceded by a newline or by a carriage return (just take it as a newline)
[\n\r] is the newline or carriage return which is matched (and later replaced with a space)
(?![\n\r]) is a negative look-ahead that tells the regex that any newline to be matched should not be followed by another newline or carriage return.
In essence, this replaces the blank, new lines which are not followed by another newline - with a space.
You can try this too,
(?m)(?!^\s*$)(^[^\n]*)\n(?!^\s*$)
Demo,,, in which matches all lines which are not empty and not followed by empty line and remove all matched newline character (\n).
But, in notepad++, you must consider carrige return(\r) with newline(\n). Thus,
(?m)(?!^\s*$)(^[^\n]*)\r\n(?!^\s*$)

Delphi regular expression, ignoring LineFeed in matched text

I want to search for the following regular expression
^[ ]*,$
in the following text :
,[LF]
,[LF]
My problem is that Delphi finds the expression, but the matched text doesn't include the LF.
Effectively I want to removes the lines from my source code.
I'am using TPerlRegEx with delphiXe8
In the example [LF] is the linefeed ($0D $0A)
I Tested several flags combinaisons in TPerlRegExOptions
This works perfectly in SublimeText 3
What am I missing ?
If you are using a PCRE regex, you can match zero or more spaces at the stsart of a line followed with a comma followed with a newline sequence with
(?m)^[ ]*,\R
See the regex demo. Note that (?m) is a multiline modifier making ^ match a location at the beginning of a line (after \n). \R matches any newline sequence.
Add a ? after \R to also match the last line in the text that has no newline sequence at the end.

regex I am trying to find a comma at the end of a field which has no more fields after the comma

I have a csv file comma separated file. I have opened in Notepad++
I am using the Regular Expression option from the Search\Replace dialog.
E.g. data in the file
One,two,three
One,,three
One,two,
One,two,
In row 3 there is a comma at the last field with no space.
In row 4 there is a comma at the last field with a space.
I am trying to find the comma without the space at row 3
I have tried the following regular expression [,^\s$]|[,^[a-z$]]
It finds all of the commas.
It is interesting it even finds the comma without a space. I thought ^\s means not include a space. i.e. ^ means Not, \s means space.
I would just like to find the last field at the end of the record which has a comma without a space and without any characters.
What regeular expression do i use for this?
Thanks!
You can use a simple regex to check if a comma is not followed by a space at the end of a line.
,(?! )$
or if there are multiple spaces:
,(?! *)$
or if there is just any whitespace:
,(?!\s*)$
See screenshot:
Just do that:
Find what: ,$
Make sure that "Regular expression" is checked.

regex in Notepad++ to remove blank lines

I have multiple html files and some of them have some blank lines, I need a regex to remove all blank lines and leave only one blank line.. So it removes anything more than one blank line, and leave those that are just one or none (none like in having text in them).
I need it also to consider lines that are not totally blank, as some lines could have spaces or tabs (characters that doesn't show), so I need it to consider these lines with the regex to be removed as long as it is more than one line..
Search for
^([ \t]*)\r?\n\s+$
and replace with
\1
Explanation:
^ # Start of line
([ \t]*) # Match any number of spaces or tabs, capture them in group 1
\r?\n # Match one linebreak
\s+ # Match any following whitespace
$ # until the last possible end of line.
\1 will then contain the first line of whitespace characters, so when you use that as the replacement string, only the first line of whitespace will be preserved (excluding the linebreak at the end).
This worked for me on notepad++ v6.5.1. UNICODE windows 7
Search for: ^[ \t]*\r\n
Replace with: nothing, leave blank
Search mode: Regular expression.
search for (\r?\n(\t| )*){3,}, replace by \r\n\r\n, check "Regular expression" and ". matches newline".
Tested with Notepad++ 6.2
This will replace the successive blank lines containing white spaces (or not) and replace it with one new line.
Search for
(\s*\r?\n){3,}
replace with
\r\n
You can find it yourself what you need to replace with
\n\n OR \n\r\n or \r\n\r\n etc ... now you can even modify your regular expression ^([ \t]*)\r?\n\s+$ according to your need.
I tested any of the above suggestions, always was either too less or to much deleted. So that either you got no blank line where at least one was beforehand or deleted not enough (whitespaces was left, etc.). Unfortunately I cannot write comments yet. Tested both with 6.1.5 and updated to 6.2 and tested again. depending on how mayn files there are, I would suggest use
Edit->Blank Operations->Trim trailing whitespace
Followed by Ctrl+A and
TextFX -> TextFX Edit -> Delete surplus blank lines
A Macro I tried to record didn't work. Theres even a macro for just remove trailing whitespace (Alt+Shift+S, see Settings | Shortcut Mapper... | Macros). There's a
Edit->Blank Operations->Remove unnecessary EOL and whitespace
but that deletes every EOL and puts everything in a single line.
In notepad++ v8.4.7 there is the option:
Edit > Line Operations > Remove Empty Lines (Containing Blank characters)
or
Edit > Line Operations > Remove Empty Lines
So there is no need to use a regular expressions for this. But this only works for one file at a time.
I looked for ^\r\n and click "Replace All" with nothing (empty) in "Replace with" textbox.

How to remove an entire line which matches a pattern

The following pattern matches an entire line, how do I search and remove these lines. If I leave a space in the replace string, it leaves a blank in that particular line, when I do via eclipse.
^[\t ]*<param name="logic" .*$
I don't know anything about eclipse but you may need to include the \n newline match in order to remove the line completely. Also - is it possible to replace with an empty string as opposed to a space?
^[\t ]*<param name="logic" .*\n$
To delete the line, you must also remove the line-break, not only the contents of the line.
So your Expression should end with \r\n instead of $.
Can't try it at the moment, so you will have to experiment yourself for the correct syntax.