Page 1 of 2
Replace smaller size text only in HTML file
Posted: Tue Dec 31, 2024 2:05 pm
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>
Re: Replace smaller size text only in HTML file
Posted: Wed Jan 01, 2025 1:21 am
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
- 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.
Re: Replace smaller size text only in HTML file
Posted: Wed Jan 01, 2025 10:46 pm
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?
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 12:52 am
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.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 5:54 am
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.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 12:43 pm
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 "</>").
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 3:04 pm
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.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 4:04 pm
by bbadmin
Find:
Replace:
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>".
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 4:45 pm
by luckystriko
Great! It works for replacement .“ into “.
How to apply it for ,“ to “, ?
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 5:26 pm
by bbadmin
It should work as "[.,]" matches either of those characters and $2 substitutes what matched.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 5:54 pm
by luckystriko
Well, I supposed so, but it doesn't. I checked it again.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 6:03 pm
by luckystriko
Attached is a html file that contains footnotes with both cases.
Please try it by yourself.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 7:01 pm
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.
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 7:17 pm
by luckystriko
Line 84 is with period (.). It works OK.
But in line 79, with comma (,) it doesn't. Please notice the part „On,“ ...
Re: Replace smaller size text only in HTML file
Posted: Thu Jan 02, 2025 7:27 pm
by AmigoJack
That's because
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:
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>