Replace smaller size text only in HTML file

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Replace smaller size text only in HTML file

Post by luckystriko »

Hello,
Hope someone can help with this. In HTML document opened by TextPad, I have two different sizes of text (footnotes in smaller size letters). Now I would like to replace some text in smaller font size only with no affecting normal text containing the same parts. Is there a way to handle this?
For example, footnotes look like this:

Code: Select all

<p><small> some “text”</small></p>
Last edited by AmigoJack on Wed Jan 01, 2025 1:14 am, edited 1 time in total.
Reason: moved from "HOW-TOs" forum; formatted code; casing
User avatar
AmigoJack
Posts: 548
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: Replace smaller size text only in HTML file

Post by AmigoJack »

That's a bit vague, but you could use a regular expression if you want to replace the entire content of those HTML elements:
  • search for

    Code: Select all

    <p><small>[^<]*</small></p>
  • replace with

    Code: Select all

    <p><small>whatever you want</small></p>
The regex means that as content every character but an opening angle bracket can appear zero to many times between those element tags.
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

I don't want to replace entire content within the element, just few characters.
Like this: ,“
Is there a way to replace only these characters inside the element and leave the rest as it is?
User avatar
AmigoJack
Posts: 548
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: Replace smaller size text only in HTML file

Post by AmigoJack »

Why don't you just select the whole line*? The "Replace" dialog window then automatically ticks "Scope: Selected text".

* Selecting the whole line means to also select its line break, not just from the first to the last character. In doubt select 2 lines at one.
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

It’s impossible. Actually I have a lot of html files (a book), and the content within the element are different footnotes. So I want to open them all at once (using TextPad) and replace just few specific characters like this couple: ,”
Hope it’s clear now.
User avatar
AmigoJack
Posts: 548
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: Replace smaller size text only in HTML file

Post by AmigoJack »

No, please provide an actual example. From your first example I concluded the HTML elements always look the same. And without further explanation I assume you want to replace everything. Now you want to replace only chosen characters (with what by the way?). Post a simple, an advanced and a complicated example of how it looks like now (can line breaks occur in those?) and how the result should look like. Please use BBCode to format your posts (click the fifth button with the caption "</>").
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

It's not English, but for example looks like this:

Code: Select all

<small>* „Isahar“ znači „on je nagrada (plata).“</small></p>
The content within the element is actually a footnote, and it looks different in other places.
I would like to find this: .“ And replace it with this: “. And similar case, find this: ,“ and replace it with this: “,
I know this may seem stupid, but it’s grammatically correct order. :)

No line breaks. Or at least, it doesn't matter.

This would be very easy to replace in the complete text of the html files, but it is only necessary to make replacements for the footnotes within the element.
User avatar
bbadmin
Site Admin
Posts: 897
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Re: Replace smaller size text only in HTML file

Post by bbadmin »

Find:

Code: Select all

<small>(.+)([.,])“</small>
Replace:

Code: Select all

<small>$1“$2</small>
Check that I've used the correct quote character. This will not do what you want if there is more than one such construct on a line, as it will match up to the last "“</small>".
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

Great! It works for replacement .“ into “.
How to apply it for ,“ to “, ?
User avatar
bbadmin
Site Admin
Posts: 897
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Re: Replace smaller size text only in HTML file

Post by bbadmin »

It should work as "[.,]" matches either of those characters and $2 substitutes what matched.
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

Well, I supposed so, but it doesn't. I checked it again.
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

Attached is a html file that contains footnotes with both cases.
Please try it by yourself.
Attachments
3.zip
(2.72 KiB) Downloaded 16 times
Last edited by AmigoJack on Thu Jan 02, 2025 7:21 pm, edited 1 time in total.
Reason: attaching file instead of using 3rd party hoster
User avatar
bbadmin
Site Admin
Posts: 897
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Re: Replace smaller size text only in HTML file

Post by bbadmin »

That file does not contain any instances with a comma. If I change the "." in the instance on line 84 to "," it works as expected.
luckystriko
Posts: 9
Joined: Tue Dec 31, 2024 1:37 pm

Re: Replace smaller size text only in HTML file

Post by luckystriko »

Line 84 is with period (.). It works OK.
But in line 79, with comma (,) it doesn't. Please notice the part „On,“ ...
User avatar
AmigoJack
Posts: 548
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: Replace smaller size text only in HTML file

Post by AmigoJack »

That's because

Code: Select all

“</small>
cannot be found in line 97. If after the ending quotation there may be more text you have to account for that with a third optional group:
  • Find:

    Code: Select all

    <small>([^<]+)([.,])“([^<]*)</small>
  • Replace with:

    Code: Select all

    <small>$1“$2$3</small>
Works on:

Code: Select all

      <li id="15">Staviæu neprijateljstvo izmeðu tebe i žene i izmeðu tvog semena i njenog semena. Ono* æe ti glavu zdrobiti, a ti æeš ga u petu raniti.“<p><small>* Doslovno: „On,“ seme Ženino, Hrist.</small></p></li>
      <li id="20">Posle toga, Adam je dao svojoj ženi ime Eva,* jer je ona postala majka svima živima.<p><small>* „Eva“ [hebrejski Hava] znaèi „živa.“</small></p></li>

Code: Select all

      <li id="15">Staviæu neprijateljstvo izmeðu tebe i žene i izmeðu tvog semena i njenog semena. Ono* æe ti glavu zdrobiti, a ti æeš ga u petu raniti.“<p><small>* Doslovno: „On“, seme Ženino, Hrist.</small></p></li>
      <li id="20">Posle toga, Adam je dao svojoj ženi ime Eva,* jer je ona postala majka svima živima.<p><small>* „Eva“ [hebrejski Hava] znaèi „živa“.</small></p></li>
Post Reply