DB Replacer

search and replace with regexp

10 months 4 days ago #77852

Stefan Schoch's Avatar Stefan Schoch

Hi there,

we have specific images in lots of articles I want to remove.

A typical syntax woulde be:
<p><img src="images/migrated/123/head_kurzgefasst_16.gif" alt="" /></p>
where the folder '123' and the '_16' suffix are random (can appear in several ways (numbers).

When I try the following REGEXP in regex101.com/ , the text above line is correctly found:

<p><img src="images\/migrated\/[0-9]+\/head_kurzgefasst.*\.gif" alt="" \/><\/p>\n

When I try the same syntax in DBreplacer, it says 'Suchbegriff nicht gefunden' after I add [0-9]+
searchstring found:
<p><img src="images\/migrated
searchstring NOT found:
<p><img src="images\/migrated[0-9]+

What's wrong?

Stefan

10 months 4 days ago #77854

Peter van Westen's Avatar Peter van Westen Admin

Try:

<p><img src="images/migrated/[0-9]+/head_kurzgefasst[^"]*\.gif" alt="" /></p>\s*

In the last regex you gave, you are missing the forward slash after 'migrated'.

10 months 4 days ago #77869

Stefan Schoch's Avatar Stefan Schoch

Seems to work.

Just to please my curiosity:
why is the the case that in regex101 I have to quote the forward slash and in DBreplacer this seems to be the reason that it didn't work?

regex101:

<p><img src="images\/migrated\/[0-9]+\/head_kurzgefasst[^"]*\.gif" alt="" \/><\/p>\s*

your suggestion:
<p><img src="images/migrated/[0-9]+/head_kurzgefasst[^"]*\.gif" alt="" /></p>\s*

Would that be true just for forward slashes?
What is the rule I have to follow when I want to copy/paste a in regex101 tested expression to DBReplacer?

Stefan

10 months 3 days ago #77876

Peter van Westen's Avatar Peter van Westen Admin

The reason why you need to escape them on Regex101 is because the default delimiter is set to '/'. If you change that to something else, you can see you don't have to escape them.
But escaping special characters doesn't hurt, even when not necessary. It will keep working, it's just less readable.

So the escaped forward slashes should not be the issue for DB Replacer.
Probably you had some other issue, like a missing forward slash.