I tried to find this on the forum but was unable. I hope this isn't a repeat question:
I need to 'remove' EOL characters from between 2 tags and the tags may be across multiple lines of text.
example,
Starting text:
----------------
<Expression>ajjb ;aeif j;; =
jot aldi addoao
flda- ee=10200 </Expression>
Needs to look like this:
--------------------------
<Expression>ajjb ;aeif j;; = jot aldi addo aoflda-ee=10200 /Expression>
i.e, all on one line.
I can do the "find" part using <Expression>.*\n.*</Expression>, but
I can't figure out what the 'replacement string' needs to be.
Thanks much,
-Jeff
Replacing characters between 2 character strings
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Unfortunately you can't match a variable number of EOL characters in TextPad, so you'll have to do a separate replace for text that spans 2 lines, text that spans 3 lines, and so on.
First, enable POSIX regular expression syntax in Configure > Preferences > Editor.
For text spanning 2 lines:
Find what: (<Expression>.*)\n(.*</Expression>)
Replace with: \1_\2 [replace the underscore with a space]
For text spanning 3 lines:
Find what: (<Expression>.*)\n(.*)\n(.*</Expression>)
Replace with: \1_\2_\3 [replace the underscore with a space]
For text spanning 4 lines:
Find what: (<Expression>.*)\n(.*)\n(.*)\n(.*</Expression>)
Replace with: \1_\2_\3_\4 [replace the underscore with a space]
And so on. You can match text spanning up to 9 lines in this way.
First, enable POSIX regular expression syntax in Configure > Preferences > Editor.
For text spanning 2 lines:
Find what: (<Expression>.*)\n(.*</Expression>)
Replace with: \1_\2 [replace the underscore with a space]
For text spanning 3 lines:
Find what: (<Expression>.*)\n(.*)\n(.*</Expression>)
Replace with: \1_\2_\3 [replace the underscore with a space]
For text spanning 4 lines:
Find what: (<Expression>.*)\n(.*)\n(.*)\n(.*</Expression>)
Replace with: \1_\2_\3_\4 [replace the underscore with a space]
And so on. You can match text spanning up to 9 lines in this way.
Hi jlassell,
From looking at your starting text:
You say it should look like this:
There is no way to exactly specify that in TextPad but this is close:
First, select from the menu to use "POSIX regular expression syntax":
Here is that line again, in a "code" block:
This search-replace will actually remove newlines from the end of any line that is NOT an exact match to any right-hand substring of "</Expression>"
So, lines like these will NOT join with the next line
Lines like these WILL join with the next line
If this is not acceptable, then you could perform the steps below just one time. If you like, you can record it as a macro. This will combine all sets of 2 or more lines:
First you need find a character that is NOT found anywhere in your file, or at least is not found as the last character of any line.
For this example, I used the "¤" character. You could probably use any "High-order-8-bit-character" like (Ø ¿ « » º ° ¬ § ¤ or £ ¢ €)
First, search for all lines ending in "</Expression>" and add that character ("¤") to the end like: "</Expression>¤"
Select from the menu to use "POSIX regular expression syntax":
Search-Replace ... (<F8> key):
Search-Replace ... (<F8> key):
Kevin
From looking at your starting text:
I see a discrepancy with your ending text...Starting text:
----------------
<Expression>ajjb ;aeif j;; =
jot aldi addoao
flda- ee=10200 </Expression>
You say it should look like this:
but I assume you meant this:<Expression>ajjb ;aeif j;; = jot aldi addo aoflda-ee=10200 /Expression>
It looks like what you want is to remove the EOL (newline) from the end of all lines that do NOT end with "</Expression>"<Expression>ajjb ;aeif j;; = jot aldi addoao flda- ee=10200 </Expression>
There is no way to exactly specify that in TextPad but this is close:
First, select from the menu to use "POSIX regular expression syntax":
Then choose Search-Replace ... (<F8> key):Configure -> Preferences -> Editor
[X] Use POSIX regular expression syntax
If you need to add a space between the joined lines then:Find what: ([^>]|[^n][>]|[^o]n>|[^i]on>|[^s]ion>|[^s]sion>|[^e]ssion>|[^r]ession>|[^p]ression>|[^x]pression>|[^E]xpression>|[^/]Expression>|[^<]/Expression>)\n
Replace with: \1
[X] Regular expression
[Replace All]
You need to make sure that you select all the "blue" text from the "From what:" line. If it is split onto multiple lines, you need to cut and paste it together. It does NOT contain any spaces.Find what: ([^>]|[^n][>]|[^o]n>|[^i]on>|[^s]ion>|[^s]sion>|[^e]ssion>|[^r]ession>|[^p]ression>|[^x]pression>|[^E]xpression>|[^/]Expression>|[^<]/Expression>)\n
Replace with: \1_ Replace underscore with a space
[X] Regular expression
[Replace All]
Here is that line again, in a "code" block:
Code: Select all
([^>]|[^n][>]|[^o]n>|[^i]on>|[^s]ion>|[^s]sion>|[^e]ssion>|[^r]ession>|[^p]ression>|[^x]pression>|[^E]xpression>|[^/]Expression>|[^<]/Expression>)\n
So, lines like these will NOT join with the next line
Code: Select all
ession>
ssion>
ression>
Code: Select all
abc ession>
anythingssion>
5 ression>
First you need find a character that is NOT found anywhere in your file, or at least is not found as the last character of any line.
For this example, I used the "¤" character. You could probably use any "High-order-8-bit-character" like (Ø ¿ « » º ° ¬ § ¤ or £ ¢ €)
First, search for all lines ending in "</Expression>" and add that character ("¤") to the end like: "</Expression>¤"
Select from the menu to use "POSIX regular expression syntax":
Then choose Search-Replace ... (<F8> key):Configure -> Preferences -> Editor
[X] Use POSIX regular expression syntax
Then, remove the newline from the end of all lines that do NOT end with "¤":Find what: (</Expression>)$
Replace with: \1¤
[X] Regular expression
[Replace All]
Search-Replace ... (<F8> key):
If you need to add a space between the joined lines then:Find what: ([^¤])\n
Replace with: \1
[X] Regular expression
[Replace All]
At this point you have all lines joined, (with a space if needed). Lastly, we need to remove the "¤" from the end of all the "</Expression>¤" lines:Find what: ([^¤])\n
Replace with: \1_ Replace underscore with a space
[X] Regular expression
[Replace All]
Search-Replace ... (<F8> key):
I hope this helps...Find what: (</Expression>)[¤]$
Replace with: \1
[X] Regular expression
[Replace All]
Kevin