Search
Other DB Replacer questions
Forum

DB-replacer and CHATgpt đŸ€“

Ulric Gress's Avatar Ulric Gress
Hi Peter, Regular Labs

I'm trying to use DB-Replacer in collaboration with ChatGPT, and it's actually working really well. However, there's one simple thing it can't generate a regex for, and that's this code:
<div id="block" class="product grid">
    <div class="product-item">
        <div><img src="images/produkter/fixbrik/Fixbrik-4mm-hvid.png" alt="Knudsen Kilens hvide Fixbrik 4mm" /></div>
    </div>
    <p>Knudsen Fixbrik is a spacer suitable for all types of tasks where items need to be stabilized, such as door and window installation, kitchen and bathroom element setup, skirting boards, panels, etc.</p>
    <p><img src="images/Miljo/epd-danmark.png" alt="EPD" width="300" height="226" style="display: block; margin-left: auto; margin-right: auto;" /></p>
</div>

The two free `<p>` elements inside `<div id="block" class="product grid">` need to be targeted and wrapped in a clean `<div>`, which should then be placed inside a `<div class="product-caption">`.

It should look like this:
<div id="block" class="product grid">
    <div class="product-item">
        <div><img src="images/produkter/fixbrik/Fixbrik-4mm-hvid.png" alt="Knudsen Kilens hvide Fixbrik 4mm" /></div>
    </div>
    <div class="product-caption">
        <div><p>Knudsen Fixbrik is a spacer suitable for all types of tasks where items need to be stabilized, such as door and window installation, kitchen and bathroom element setup, skirting boards, panels, etc.</p>
        <p><img src="images/Miljo/epd-danmark.png" alt="EPD" width="300" height="226" style="display: block; margin-left: auto; margin-right: auto;" /></p>
        </div>
    </div>
</div>

The regex to target <p> it gives me is: `(<div id="block" class="product grid">)(.*?)(<p>.*?<\/p>)(.*?)(<\/div>) but it is not working.

I hope you can shed some light on this.

Best,
Ulric
Peter van Westen's Avatar Peter van Westen ADMIN
Maybe something like:
(<div id="block" class="product grid">\s*<div class="product-item">.*?</div>\s*</div>\s*)(<p>.*?)(</div>)
Replace with:
\1<div class="product-caption"><div>\2</div></div>\3
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Unfortunately, that regex does not capture the two free `<p>` elements—"search string not found." That’s really strange and very difficult to figure out.
Peter van Westen's Avatar Peter van Westen ADMIN
www.phpliveregex.com/p/N5y
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Sorry, I’m not quite following what you mean—could you elaborate? I’m just seeing my old code in the left window—but it’s DB-Replacer that should find and target those <p> elements and replace them, not the regex... I’m confused. đŸ€”
Peter van Westen's Avatar Peter van Westen ADMIN
You are using a Regular Expressions search in DB Replacer. If not, you should be! Switch on the Regular Expressions option.
That link shows that the Regular Expressions finds the given content. So it should work.
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Yes, I totally get it—there must be something else causing the issue! đŸ€”

DB-Replacer

Where:
`catid = 235`

Search:
(<div id="block" class="product grid">\s*<div class="product-item">.*?</div>\s*</div>\s*)(<p>.*?)(</div>)
With Regular Expression selected.

But it doesn’t capture the two free `<p>` elements, so I can’t move forward with replacing them!
Peter van Westen's Avatar Peter van Westen ADMIN
Can you give me (super) admin access so I can take a look?
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
It would be cool if you could take a look—I’m working locally with MAMP but will upload the test site to a subdirectory in a moment.
Peter van Westen's Avatar Peter van Westen ADMIN
I would need to see it live and be able to play around.
So if you can give me (super) admin access, I can help you further.
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
thanks 🙏 one moment...
Ulric Gress's Avatar Ulric Gress
Confidential information:
(hidden)


The site is now on my domain—it concerns the **Flexbrik** category with **catid = 235**. It contains **7 Flexbrik articles**, where I am restructuring the layout so I can roll it out across all **5 languages**. That’s why it’s important to get the correct **search string (RegEx)** saved for later use with **DB-Replacer**.
Peter van Westen's Avatar Peter van Westen ADMIN
Try:
(<div id="block" class="product grid">\s*<div class="product-item">.*?</div>\s*</div>\s*)
((?:<p>.*?</p>\s*)+\s*)(</div>)
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Yes, much better, but it only captures 5 live, locally captures 6 and it should capture 7 in total? How can that be? Could it be that the markup is not exactly the same?
Peter van Westen's Avatar Peter van Westen ADMIN
Your server seems to be naggy about whitespace.
This works:
(<div id="block" class="product grid">\s*<div class="product-item">\s*.*?\s*</div>\s*</div>\s*)
((?:<p>\s*.*?\s*</p>\s*)+\s*)(</div>)
But normally you wouldn't need all those '\s*' there. Probably a weird php or mysql setting on your server.
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Fantastic Peter, 1000 thanks!!! Now it captures both locally and live with 7 articles. I will try your replacement later to see if I can get those <p> elements in place – really cool help!

DB-Replacer is indeed an incredibly powerful tool! It makes tasks like this so much easier and more efficient, especially when dealing with large-scale changes across a site.

Best regards Ulric
Ulric Gress's Avatar Ulric Gress
Hello again 🙃 We have this last challenge, a more advanced one this time. Maybe you can help. ChatGPT has come up with many versions to match this HTML structure, both with and without `\s*`, but it’s not getting DB-Replacer to capture it. Very strange! We need to match this:
<div class="col-md-6 tech info">
    <h3>Mere information</h3>
    <div>
        <h3>Tekniske data</h3>
        <ul>
            <li>MĂ„l: 1x45x75 mm</li>
            <li>Fixbrikkerne fÄs i tykkelserne <br />1-2-3-4-5-10-12 mm</li>
            <li>{snippet id="220"}</li>
            <li>{snippet id="227"}</li>
            <li>{snippet alias="epd-knudsen-kilen-hdpe"}</li>
            <li>{snippet alias="epd-appendix-knudsen-kilen-hdpe"}</li>
        </ul>
    </div>
    <div>
        <h3>Anvendelse</h3>
        <ul>
            <li>{snippet id="30"} – Produkter og anvendelse.</li>
            <li>{snippet id="228"}</li>
            <li>Fixbrikken er sÊrligt velegnet til montage pÄ lodrette flader, da den er konstrueret som en splitbrik med finner i midten, der sikrer et stabilt greb om skruen ved enhver montage.</li>
            <li>De forskellige farvekodede tykkelser gĂžr det nemt og hurtigt at udfĂžre nĂžjagtige montagearbejder.</li>
        </ul>
    </div>
    <div>
        <h3>TUN/DB / Varenummer</h3>
        <ul>
            <li>2458219 / 973305001</li>
        </ul>
    </div>
</div>

I tried this among others without success:
<div class="col-md-6 tech info">\s*<h3>Mere information</h3>\s*<h4>Tekniske data</h4>\s*<ul>(.*?)</ul>\s*<h4>Anvendelse</h4>\s*<ul>(.*?)</ul>\s*<h4>TUN/DB \/ Varenummer</h4>\s*<ul>(.*?)</ul>\s*</div>

Best, Ulric
Peter van Westen's Avatar Peter van Westen ADMIN
...
    <h3>Mere information</h3>
    <div>
        <h3>Tekniske data</h3>
        ...
...<h3>Mere information</h3>\s*<h4>Tekniske data</h4>...
There is a <div> tag there inbetween. And those are <h3> tags, not <h4> tags.

I recommend you start with the first tag:
<div class="col-md-6 tech info">
And then extend per tag/part, until you have everything. That way you know where stuff starts not matching.
Please post a rating at the Joomla! Extensions Directory
Ulric Gress's Avatar Ulric Gress
Thanks – yes, it’s probably messing a bit with things that have already been replaced in the test, sorry. I’ll need to start over and try your good suggestion, it makes sense... / Ulric
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription