Topic on Extension talk:Replace Text

can't replace HTML-like strings

8
217.132.232.233 (talkcontribs)

I'm trying to replace HTML-like tags spread across hundreds of pages in my wiki. I'm using regular expressions, e.g.

<repeat>(.*?)</repeat>

but keep getting Wikimedia\Rdbms\DBQueryError error suppoedly indicating a software bug. Is there a way around this?

My version is MW 1.30.1, PHP 5.5.9, MySQL 5.7.25 (with ReplaceText for MW 1.30 of course)

Ciencia Al Poder (talkcontribs)

Can you temporarily set $wgShowSQLErrors = true; in LocalSettings.php and repeat the action, and see what's the error message?

217.132.232.233 (talkcontribs)

It was already set, nothing shows except what I already mentioned (error occured when querying DB, which might indicate a bug in software "Wikimedia\Rdbms\DBQueryError") ~~~~

FreedomFighterSparrow (talkcontribs)

Trying to reproduce this issue, the error that shows is this:

Function: ReplaceTextSearch::doSearchQuery
Error: 1139 Got error 'repetition-operator operand invalid' from regex

It looks like this is a limitation in MySQL's implementation - you cannot use the non-greedy wildcard, '*?'. It looks like MySQL 8 might have a better implementation of Regex, but I cannot test at the moment.

217.132.232.233 (talkcontribs)

So...is there a way around this limitation? ~~~~

FreedomFighterSparrow (talkcontribs)

That's actually a regex question, more than a mediawiki question... If you don't have any other tags in between those, you can simply do this: <repeat>([^<]*)</repeat>

This obviously won't work if there's any '<' in the text between the "repeat" tags. In that case, my regex knowledge is exhausted, and I would suggest you ask that question on StackOverflow or the like.

217.132.232.233 (talkcontribs)

ok, thanks!

Johnywhy (talkcontribs)

can you use backslash escape character?

Reply to "can't replace HTML-like strings"