This is a bit more complicated (to me!) than similar questions.
I'm trying to copy some dates with Regex in some old HTML, into another location, but have a problem with the replacements extending outside the required block, when I repeat the search and replace.
In the example below, each block <ul> .. </ul> represents a specific date that is included with first <li>..<b>. I want to copy "13 Oct 2005" into the subsequent <li>..<b>, and likewise, "14 Oct 2005" into the subsequent <li>..<b> too, but not outside its <ul> .. </ul> block.
This I can do using the following Regex (used by Funduc's Search & Replace utility for Windows, apparently "a subset of UNIX grep notation)":
Search: <li>+[0-9] *<b>*[]<li><b>
Replace: <li>%1 %2\<b>%3\<li>%1 %2\<b>
+[0-9] is one or more numeric; * is any alphabetical; *[] is anything; %1 .. %4 are replacement positions.
Here is my original HTML
<ul>
<li>13 Oct 2005<b>Title One</b>
Some text
<p>
<li><b>Title Two</b>
Some more text
<p>
</ul>
<ul>
<li>14 Oct 2005<b>Title 3</b>
Another line of text
<p>
<li><b>Title 4</b>
Yet another line of text
<p>
<li><b>Title 5</b>
Some text
<p>
</ul>
After my first script run, this correctly gives me:
<ul>
<li>13 Oct 2005<b>Title One</b>
Some text
<p>
<li>13 Oct 2005<b>Title Two</b>
Some more text
<p>
</ul>
<ul>
<li>14 Oct 2005<b>Title 3</b>
Another line of text
<p>
<li>14 Oct 2005<b>Title 4</b>
Yet another line of text
<p>
<li><b>Title 5</b>
Some text
<p>
</ul>
But after my second script run, the 13 Oct 2005 is added incorrectly to the next <ul> .. <ul> block:
<ul>
<li>13 Oct 2005<b>Title One</b>
Some text
<p>
<li>13 Oct 2005<b>Title Two</b>
Some more text
<p>
</ul>
<ul>
<li>14 Oct 2005<b>Title 3</b>
Another line of text
<p>
<li>14 Oct 2005<b>Title 4</b>
Yet another line of text
<p>
<li>13 Oct 2005<b>Title 5</b> <-- wrong !!!
Some text
<p>
</ul>
I have about 20,000 <ul> .. <ul> blocks (hence the script), and each block contains between 1-10 <li><b> tags with titles. I assumed it couldn't be done in one pass.