Search
Other DB Replacer questions
Forum

Pro version/Regular Expressions for Tooltip Replacement?

Kevin Ballestrini's Avatar Kevin Ballestrini
Hi Peter,

I have thousands of tooltips across hundreds of pages that need to be updated to the "new" formatting.

They are either in the form of

{tip XXX::YYY}

or simply {tip ZZZ}

These obviously have to become {tip title="XXX" content="YYY"} or {tip content="ZZZ"}

Can the pro version of DB Replacer with Regular Expressions do this easily? What would be the most efficient way to do this? Thanks!
Peter van Westen's Avatar Peter van Westen ADMIN
You can do this with DB Replacer Pro.

For instance, to convert {tip XXX::YYY} to {tip title="XXX" content="YYY"} you can do this with Regular Expressions:
\{tip ([^\}]+)::([^\}]+)\}
Replace with:
{tip title="\1" content="\2"}
Please post a rating at the Joomla! Extensions Directory
Kevin Ballestrini's Avatar Kevin Ballestrini
Ok, I've been doing this manually up to this point. This could be a game changer. Thanks!

Edit: So on a test page using the where string, it worked flawless to convert XXX::YYY to the new string.

I must be doing something incorrectly though on the conversion of single {tip ZZZ} because it wants to replace all of the converted tips as well. Will those just have to be done manually?
Peter van Westen's Avatar Peter van Westen ADMIN
\{tip ([^\}"]+)\}
Replace with:
{tip content="\1"}
Please post a rating at the Joomla! Extensions Directory
Kevin Ballestrini's Avatar Kevin Ballestrini
Awesome; it works great with {tip "words go here"} to do the single replacements, but it's still struggling to replace {tip words go here}.

But that's perfectly ok at this point, that's a small fraction of the tips. This has made my day.
Peter van Westen's Avatar Peter van Westen ADMIN
I guess you mean the other way round... So with the quotes is not working???
Please post a rating at the Joomla! Extensions Directory
Kevin Ballestrini's Avatar Kevin Ballestrini
Yeah, I realize now there's another complication that occasionally happens... There might be a situation like

{tip word::more "words" or "different words" do this} and any kinds of quotes in tips breaks the page utterly because "" inside of {tip title="title" content="This is a "word" that someone uses"} causes all sorts of issues.

For context, this is all language learning materials.
Peter van Westen's Avatar Peter van Westen ADMIN
Yeah, that's a little difficult, as you'll have to escape the quotes, like:
{tip title="title" content="This is a \"word\" that someone uses"}

You could solve this by running below replacement multiple times until it is not found anymore:
(\{tip title="[^"]+" content="[^\}]*?[^\\\}])("[^\}]*"\})
\1\\\2
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
If you start fresh (so roll back to the original content), I think you can correct all using these steps:

1: Place all into the content attribute
\{tip ([^\}]+)\}
{tip content="\1"}

2: Fix the quotes inside the content attribute
(\{tip content="[^\}]*?[^\\\}])("[^\}]*"\})
\1\\\2
(repeat until no more results)

3: Move the part before the '::' from the content attribute to the title attribute
\{tip content="([^\}]*?)::([^\}]*)"\}
{tip title="\1" content="\2"}
Please post a rating at the Joomla! Extensions Directory
Kevin Ballestrini's Avatar Kevin Ballestrini
Wow, ok -- thanks for detailing that out. I'll see if I can get that to work better. Thanks again for this help, I think you saved me a few hundred hours of work this morning.
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription