Hi,
Is it possible to combine 2 line having the same 4 bytes in textpad?
EX.
0001ABCDEFG
0001HIJKLMNO
0002PQRSTUV
Output
0001ABCDEFGHIJKLMNO
0002PQRSTUV
TIA!
Combine lines with the same first 4 bytes
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Ths solution provided by kengrubb does work but it is limited by having to hard code the first four characters.
I wanted to overcome that, so I thought that this would work for any 4 char string:
Search for: ^(.{4})(.*)\n\1(.*)$
Replace with: \1\2\3
But surprisingly, I got an error message that this was an invalid RegEx.
The Help file does mention that TextPad supports using Tagged Expressions in the Search string.
Search for : ^(.{4})(.*)\1
on this string: 0001ABCDE0001FGHI, I do get a match up to "FGHI".
But my solution for the original problem does not work, it seems because it has an "\n" in the search string.
I know that TextPad's RegEx has some strange limitations, and does not wrap lines, but searches using hard coded \n do work. But apparently, using \1-\9 only works on a line before a \n, and cannot be used on a subsequent line. Not sure if this is a bug or if it is normal for TextPad.
I wanted to overcome that, so I thought that this would work for any 4 char string:
Search for: ^(.{4})(.*)\n\1(.*)$
Replace with: \1\2\3
But surprisingly, I got an error message that this was an invalid RegEx.
The Help file does mention that TextPad supports using Tagged Expressions in the Search string.
This does workFor example \(tu\) \1 matches the string "tu tu".
Search for : ^(.{4})(.*)\1
on this string: 0001ABCDE0001FGHI, I do get a match up to "FGHI".
But my solution for the original problem does not work, it seems because it has an "\n" in the search string.
I know that TextPad's RegEx has some strange limitations, and does not wrap lines, but searches using hard coded \n do work. But apparently, using \1-\9 only works on a line before a \n, and cannot be used on a subsequent line. Not sure if this is a bug or if it is normal for TextPad.
Hope this was helpful.............good luck,
Bob
Bob
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
From that behaviour, and also from the fact that \n can't be used in a quantified way (like \n+ or similar) I guessed a long time ago that Textpad splits the regular expression at \n and then applies the first part - if it matches, it applies the second part to the next line, if that also matches, it applies the third part to the next line and so on ...
As each line seems to be treated by its own regex, that would explain why back references do not work - the regex for the second line doesn't know what to refer to if the () is in the regex for the first line ...
As each line seems to be treated by its own regex, that would explain why back references do not work - the regex for the second line doesn't know what to refer to if the () is in the regex for the first line ...
Changing the focus slightly, I tried this in WE using the Perl RE syntax.
Search for:
^(.{4})(.*)\n\1
Replace with:
\1\2
However, I'm not nearly as capable with Perl RE syntax as I am with Posix extended syntax.
It's not throwing an error, but it's not finding the RE. If there's someone here who's more Perl RE fluent ...
Search for:
^(.{4})(.*)\n\1
Replace with:
\1\2
However, I'm not nearly as capable with Perl RE syntax as I am with Posix extended syntax.
It's not throwing an error, but it's not finding the RE. If there's someone here who's more Perl RE fluent ...
(2[Bb]|[^2].|.[^Bb])
That is the question.
That is the question.
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
WildEdit is unfriendly in its handling of line endings: you have to be explicit and precise about them. Your search expression is good for Linux line endings (LF). For Windows line endings (CR,LF) you need to search for
^(.{4})(.*)\r\n\1
To handle either Linux or Windows line endings you might use
^(.{4})(.*)\r?\n\1
For Perl replacement syntax you should really use
$1$2
but WildEdit seems to accept the backslashes.
^(.{4})(.*)\r\n\1
To handle either Linux or Windows line endings you might use
^(.{4})(.*)\r?\n\1
For Perl replacement syntax you should really use
$1$2
but WildEdit seems to accept the backslashes.