New line every n characters
-
@Alan-Kilborn said in New line every n characters:
find: (?-s).{500}
repl: ${0}\r\n
Tick the Wrap around box, and press Replace All buttonI would make some changes:
(?-s)
is not required as no newline characters in file- Untick wrap around button as important the regex starts in very first position.
- Cursor MUST be in first position of file BEFORE regex run.
All because OP stated it is all serial information, so ALL on one line.
Likely without these changes it will work out OK but if OP had moved through file first before starting the regex the cut points will be in the wrong positions.
My 2c worth
Terry -
Well, I use
(?-s)
as a “safety measure”. If I don’t intend line-ending characters to be matched by the.
, I preamble with(?-s)
. For me, it’s a good habit to always specify(?s)
or(?-s)
when using.
. And, I believe it is a good habit for forum postings as well, so that the. matches newline
checkbox state doesn’t have to be provided as a separate item.But sure, since there are no line-endings in the OP’s data…
Untick wrap around button as important the regex starts in very first position.
I don’t understand what is meant here. Well, I understand how to untick, but I don’t know what the rest means or how it is relevant.
Cursor MUST be in first position of file BEFORE regex run.
Hmmm, having Wrap around ticked negates the need for this, and is simpler than telling a user to move the caret.
Perhaps you don’t know that a Replace All search with Wrap around ticked does one transit through the file, starting at the very top, no matter where the caret starts out at?
Maybe you do know, but I’ll keep going for those that don’t…
Prove it thusly:
- Find data for both cases:
abcdefghijklmno
- Replace data for both cases:
@
- Caret starting location for both cases: between the
b
and thec
.
Case 1:
- Tick Wrap around
- Press Replace all
Result:
@klmno
Case 2:
- Untick Wrap around
- Press Replace all
Result:
ab@mno
The key point here is that for Case 1 the search matches at start of file, NOT from the caret.
- Find data for both cases:
-
@Alan-Kilborn said in New line every n characters:
Prove it thusly:
Find data for both cases: abcdefghijklmno
Replace data for both cases: @
Caret starting location for both cases: between the b and the c.Reading my own posting I am stunned to see that I left off a very important part of the instructions, applicable to both Case 1 and 2:
- Put
(?-s).{10}
in the Find what box
And of course this doesn’t make any sense unless we’re in Regular expression for the Search mode.
- Put
-
@Alan-Kilborn said in New line every n characters:
Perhaps you don’t know that a Replace All search with Wrap around ticked does one transit through the file, starting at the very top, no matter where the caret starts out at?
Oh, no I hadn’t realised that important fact. I suppose in tests I have always identified that as a potential issue when using the Replace button. Thank you for pointing out that important fact.
So then the wrap around being ticked is actually redundant with a Replace All button press.
Terry
-
@Alan-Kilborn said in New line every n characters:
Perhaps you don’t know that a Replace All search with Wrap around ticked does one transit through the file, starting at the very top, no matter where the caret starts out at?
I just checked the manual and there it says:
Replace All: Replaces all matches from the active location onward (following the Backward direction and Wrap around settings as appropriate).That then seems to be wrong unless my interpretation is wrong of what active location means.
Terry
-
@Terry-R said in New line every n characters:
So then the wrap around being ticked is actually redundant with a Replace All button press.
Sorry, I had read it differently the first time.
So Replace All with Wrap Around ticked starts at the first position in the file.
Replace All button with Wrap Around NOT ticked starts at the current position.From your example I see it works. The manual does NOT appear to outline this VERY important change. At least not where Wrap Around and Replace All are described!
Is this something that needs to be amended?
Terry
-
Hi, @terry-r, @alan-kilborn, and All,
Let’s consider this simple text, below, in a new Windows tab
123 456 789
with the last line without CRLF. So, the exact contents are the
13
bytes1 2 3 CR LF 4 5 6 CR LF 7 8 9
FIRST test :
-
Move the caret right after digit
5
-
Run the regex S/R :
-
SEARCH
(?s).{3}
-
REPLACE
@
-
Untick the
Wrap around
option -
Click on the
Replace All
button
-
we get the text :
123 45@@
without CRLF after the last
@
char. Remember that theCR
andLF
characters count for ONE char because of the(?s)
syntax !-
Then, move the caret at the very beginning of file, right before the digit
1
-
Run the regex S/R :
-
SEARCH
(?s).{3}
-
REPLACE
@
-
The
Wrap around
option is still unticked -
Click on the
Replace All
button
-
The text is now changed as :
@@@
without CRLF after the last
@
charSo, it’s the final result if we suppose that the regex engine goes from the digit
6
to the digit9
, then from digit1
to digit5
SECOND test :
-
Move, again, the caret right after digit
5
-
Run the same regex S/R :
-
SEARCH
(?s).{3}
-
REPLACE
@
-
Tick the
Wrap around
option ( IMPORTANT ) -
Click on the
Replace All
button
-
we get the text :
@@@@9
without CRLF after the
9
digitAnd this result proves that, although the caret was initially between digits
5
and6
, due to theWrap around
option ticked, the caret is internally moved at the very beginning of file and, then, the regex engine goes from digit1
to digit9
to process contentsAs the total number of bytes is
13
, this means that the search regex had sliced the text in4
ranges of3
chars, leaving the9
digit alone, at the end ! Just logical ;-))Best Regards,
guy038
-
-
@Terry-R said in New line every n characters:
So Replace All with Wrap Around ticked starts at the first position in the file.
Replace All button with Wrap Around NOT ticked starts at the current position.
From your example I see it works.My earlier postings were not so great :-(
But I see that you got the point.I’m not sure @guy038 's posting adds anything, except as another example of proof of how it works?
The manual does NOT appear to outline this VERY important change. At least not where Wrap Around and Replace All are described!
Is this something that needs to be amended?Yes, if that’s what the manual says, then I think it could be better.
What does @PeterJones think, as our resident manual guru?BTW, a posting somewhere here long ago (I think) said to think about Wrap around ticked as meaning “Entire document” in this (Replace All) circumstance, and I’ve always remembered that, as it seems to be appropriate.
-
@Alan-Kilborn said in New line every n characters:
@Terry-R said in New line every n characters:
So Replace All with Wrap Around ticked starts at the first position in the file.
Replace All button with Wrap Around NOT ticked starts at the current position.I disagree. AFAIK, if my cursor is on line 3 of a 5-line file, and there is a sequence that will match on all 5 lines, and I hit replace all with wrapping enabled, the first replacement will be on line 3, the second on line 4, the third on line 5, the fourth on line 1, and the fifth on line 2. I cannot think of a regex offhand that would cause that to be different than starting a replace-all at the begining of a file… but there might be one.… experiment …
Nope, I was wrong.
Data:
one two three four five fourteen something fifteen
regex = FIND:
(?i-s)\b((?<!☺ )f\w+)
=> REPLACE:${1}☺
If my original assertion, and what is implied in the manual, were true, then starting with the cursor before
four
vs. beforefive
and hitting Replace All would come up with different answers. Between thefour
andfive
, it would add a smiley tofive
if it really started wherever the cursor was, but would only add a smiley afterfour
if it really started from the beginning.With wrap-around enabled, it only puts the smiley after the
four
, not thefive
; without wrap-around, it puts it after thefive
if the cursor is between.Is this something that needs to be amended?
Yes, if that’s what the manual says, then I think it could be better.
What does @PeterJones think, as our resident manual guru?
What I thought is different than what I could prove. I thought wrong.
usermanual issue #178 submitted. -
@PeterJones said in New line every n characters:
usermanual issue #178 submitted.
I’ve taken this to a new discussion located here.
As far as the OP’s problem, this has been solved. I did not wish to further muddy these waters and have instead continued with a new post.Terry
-
I am stunned by the quantity and quality of help available in this community in a very short time! Thank you very much to everyone :)