Multiple-line collapse in Notepad++ - editor

I want to use notepad++ to do multiple-line collapse. What I mean is that I am looking for a simple operation to turn
1
2
3
4
into
1 2
3 4

How about:
Ctrl+H
Find what: (.+)\R(.+)(\R)
replace with: $1 $2$3
Replace all
Where \R stands for any kind of linebreak.
This will replace a linebreak between 2 lines by these 2 lines separated by a space.

Related

Look for a second carriage return using InDesign Grep

I am looking for a grep expression for InDesign.
I have the following lines:
This is Line 1
This is Line 2
This is Line 3
This is Line 4
This is Line 5
This is Line 6
Line 1 and 2 will be right indent.
Line 3 and 4 will be left indent.
Line 5 and 6 will again be right indent.
There is a carriage return after each line, except line six.
I want to target the carriage return after line 2, 4 and replace it with some other character or forced linebreak.
How can I do that in grep?
Find what: (.+\r.+)\r
Change to: $1#
where # is your symbol.

Ckeditor 5 removing line-breaks from copying data

I use classic default ckeditor 5 build.
The problem is if I copy from notepad text like:
1
2
3
In editor I give result:
1 2 3
If I copy next text:
1
2
3
In editor I give:
1
2
3
Why ckeditor removing one line-break per line ?
You encountered something that can be considered a bug or a missing feature.
Single \n line characters, which are converted to <br> on paste are lost due the fact that CKEditor 5 doesn't support soft-line breaks yet.
On the other hand, not everyone need to load the soft-line break feature so, even if we'll introduce it, the problem will occur for these users. Hance, perhaps the plain text to HTML conversion should work differently. Or be configurable.
More info https://github.com/ckeditor/ckeditor5/issues/766

With notepad++, if "Find All" strings match multiple times in 1 line, output shows duplicated lines

I would like to know how to prevent notepad++ to output duplicated lines when I execute Find All.
Here is sample text file.
aaa aaa
bbb bbb
ccc ccc
I put "aaa" as search strings and click "Find All in Current Document".
Then output will be like this. Line 1 appears 2 times because strings "aaa" matched 2 times in line 1.
Search "aaa" (2 hits in 1 file)
new 2 (2 hits)
Line 1: aaa aaa
Line 1: aaa aaa
It is bothering to remove duplicated lines later. Is there any good method to prevent duplicated lines?
Thanks in advance!
I have never heard of a way to make the "Find result" window remove "duplicate lines". They originate from the multiple hits on the same line.
To stop the dupes from appearing is to make sure you only find the last occurrence of the string on a line.
To do this, you need to use a regex in the following form:
(\Qaa.a\E)(?!.*\1)
where <YOUR_VALUE> is aaa. The \Q and \E operators are necessary to make the regex engine treat all chars between them as literal characters. The (...) will capture the search string into Group 1 and the (?!.*\1) negative lookahead will fail all matches that are followed with the same search string on the line (as .* matches any 0+ chars other than linebreak symbols).

RAILS 3 CSV "Illegal quoting" is a lie

I've hit a problem during parsing of a CSV file where I get the following error:
CSV::MalformedCSVError: Illegal quoting on line 3.
RAILS code in question:
csv = CSV.read(args.local_file_path, col_sep: "\t", headers: true)
Line 3 in the CSV file is:
A-067067 VO VIA CE 0 8 8 SWCH Ter 4, Loc Is Here, Mne, Per Fl Auia/Sey IMAC NEK_HW 2011-03-09 09:47:44 2011-03-09 11:50:26 2011-01-13 10:49:17 2011-02-14 14:02:43 2011-02-14 14:02:44 0 0 771 771 46273 "[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC" SOME_TEXT SOME_TEXT N/A Name Here RESOLVED_CLOSED RESOLVED_CLOSED
UPDATE: Tabs don't appear to have come across above. See pastebin RAW TEXT: http://pastebin.com/4gj7iUpP
I've read numerous threads all over StackOverflow and Google about why this is and I understand that. But the CSV row above has perfectly legal quoting does it not?
The CSV is tab delimited and there is only a tab followed by the quote on either side of the column in question. There is 1 quote in that field and it is double quoted to escape it. So what gives? I can't work it out. :(
Assuming I've got something wrong here, I'd like the solution to include a way to work around the issue as I don't have control over how the CSV is constructed.
This part of your CSV is at fault:
46273 "[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC" SOME_TEXT
At least one of these parts has a stray space:
46273 "
" SOME_TEXT
I'd guess that the "3" and the double are supposed to be separated by one or more tabs but there is a space before the quote. Or, there is a space after the quote on the other end when there are only supposed to be tabs between the closing quote and the "S".
CSV escapes double quotes by double them so this:
"[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC"
is supposed to be a single filed that contains an embedded quote:
[O/H 15/02] B270 W31 "TEXT TEXT 2 X TEXT SWITC
If you have a space before the first quote or after the last quote then, since your fields are tab delimited, you have an unescaped double quote inside a field and that's where your "illegal quoting" error comes from.
Try sending your CSV file through cat -t (which should represent tabs as ^I) to find where the stray space is.

Remove hard line breaks from text with Ruby

I have some text with hard line breaks in it like this:
This should all be on one line
since it's one sentence.
This is a new paragraph that
should be separate.
I want to remove the single newlines but keep the double newlines so it looks like this:
This should all be on one line since it's one sentence.
This is a new paragraph that should be separate.
Is there a single regular expression to do this? (or some easy way)
So far this is my only solution which works but feels hackish.
txt = txt.gsub(/(\r\n|\n|\r)/,'[[[NEWLINE]]]')
txt = txt.gsub('[[[NEWLINE]]][[[NEWLINE]]]', "\n\n")
txt = txt.gsub('[[[NEWLINE]]]', " ")
Replace all newlines that are not followed by or preceded by a newline:
text = <<END
This should all be on one line
since it's one sentence.
This is a new paragraph that
should be separate.
END
p text.gsub /(?<!\n)\n(?!\n)/, ' '
#=> "This should all be on one line since it's one sentence.\n\nThis is a new paragraph that should be separate. "
Or, for Ruby 1.8 without lookarounds:
txt.gsub! /([^\n])\n([^\n])/, '\1 \2'
text.gsub!(/(\S)[^\S\n]*\n[^\S\n]*(\S)/, '\1 \2')
The two (\S) groups serve the same purposes as the lookarounds ((?<!\s)(?<!^) and(?!\s)(?!$)) in #sln's regexes:
they confirm that the linefeed really is in the middle of a sentence, and
they ensure that the [^\S\n]*\n[^\S\n]* part consumes any other whitespace surrounding the linefeed, making it possible for us to normalize it to a single space.
They also make the regex easier to read, and (perhaps most importantly) they work in pre-1.9 versions of Ruby that don't support lookbehinds.
There is more to formatting (turning off word wrap) than you think.
If the output is a result of a formatting operation, then you should go by
those rules to reverse engineer the original.
For instance, the test you have there is
This should all be on one line
since it's one sentence.
This is a new paragraph that
should be separate.
If you removed just the single newlines only, it would look like this:
This should all be on one line since it's one sentence.
This is a new paragraph thatshould be separate.
Also, other formatting such as intentional newlines will be lost, so something like:
This is Chapter 1
Section a
Section b
Turns into
This is Chapter 1 Section a Section b
Finding the newline in question is easy /(?<!\n)\n(?!\n)/
but, what do you replace it with.
Edit: Actually, its not that easy even to find standalone newlines, because visually they sit amongst hidden from view (horizontal) whitespaces.
There are 4 ways to go.
Remove newline, keep the surrounding formatting
$text =~ s/(?<!\s)([^\S\n]*)\n([^\S\n]*)(?!\s)/$1$2/g;
Remove newline and formatting, substitute a space
$text =~ s/(?<!\s)[^\S\n]*\n[^\S\n]*(?!\s)/ /g;
Same as above but ignore newline at beginning or end of string
$text =~ s/(?<!\s)(?<!^)[^\S\n]*\n[^\S\n]*(?!$|\s)/ /g;
$text =~ s/(?<!\s)(?<!^)([^\S\n]*)\n([^\S\n]*)(?!$|\s)/$1$2/g;
Example breakdown of regex (this is the minimum required just to isolate a single newline):
(?<!\s) # Not a whitespace behind us (text,number,punct, etc..)
[^\S\n]* # 0 or more whitespaces, but no newlines
\n # a newline we want to remove
[^\S\n]* # 0 or more whitespaces, but no newlines
(?!\s)/ # Not a whitespace in front of us (text,number,punct, etc..)
Well, there is this:
s.gsub /([^\n])\n([^\n])/, '\1 \2'
It won't do anything to leading or trailing newlines. If you don't need leading or trailing white space at all, then you will win with this variation:
s.gsub(/([^\n])\n([^\n])/, '\1 \2').strip
$ ruby -00 -pne 'BEGIN{$\="\n\n"};$_.gsub!(/\n+/,"\0")' file
This should all be on one line since it's one sentence.
This is a new paragraph thatshould be separate.

Resources