Resource icon

Post Content Find / Replace 1.0.0

No permission to download
I've simplified the regex slightly but you might want to do a few searches to see if there's any alternative URLs such as https:// or youtu.be links if so, the regex can probably be adjusted but this should cover the basic case for now and stop it from being so greedy:
Code:
/\[url=http:\/\/(?:www\.)*+youtube\.com\/watch\?v=([\w\-]+)\].+\[\/url\]/siU
 
I've simplified the regex slightly but you might want to do a few searches to see if there's any alternative URLs such as https:// or youtu.be links if so, the regex can probably be adjusted but this should cover the basic case for now and stop it from being so greedy:
Code:
/\[url=http:\/\/(?:www\.)*+youtube\.com\/watch\?v=([\w\-]+)\].+\[\/url\]/siU

Brilliant, that worked perfectly. Thanks!
 
1. How many million posts do you need to trigger timeout on post replace?
2. Is "Quick Find" field value sensitive case?

Update :
8 million posts and i got timeout.
I used this instead :)
Code:
UPDATE xf_post
SET message = REGEXP_REPLACE(message, '(?)replace from', 'replace into');
 
Last edited:
Thanks for the awesome addon, it helped me alot, but maybe you could help me with one last regex:

I'm converting from burning board via mybb and since burning board uses html for quotes, i have some issues.

The current regex works for 95% of the quotes:
Code:
/\<woltlab-quote data-author=\"(.*)\"\s.*\?postID=(\d*).*\">(.*)<\/woltlab-quote>/sim

The problem howerver is that 'date-author' and 'postId?=' are in a switched position in some cases and that breaks those quotes since the regex matches it directly.

Heres is a working example:
https://regex101.com/r/48RvUQ/1

So sometimes date-author is in the place of data-link and that causes a issue. i'd like to have a regex that does the same thing as the one above, but for both cases....
 
Hi,
I test this addon my regular expression is correct, but I have an error

https://regex101.com/r/Olxz22/1

Code:
ErrorException: [E_WARNING] preg_match_all(): Delimiter must not be alphanumeric or backslash in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
XF::handlePhpError()
preg_match_all() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13
 
Solved with delimiter : #\[sketchfab\]https*?:\/\/sketchfab.com\/models\/(.*)\[\/sketchfab\]#

But i have new error :

Code:
InvalidArgumentException: Attempted to convert NULL to string/binary [content_title] in src/XF/Mvc/Entity/Entity.php at line 685
XF\Mvc\Entity\Entity->_castValueToType() in src/XF/Mvc/Entity/Entity.php at line 572
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 502
XF\Mvc\Entity\Entity->__set() in src/XF/ModeratorLog/Post.php at line 60
XF\ModeratorLog\Post->setupLogEntityContent() in src/XF/ModeratorLog/AbstractHandler.php at line 67
XF\ModeratorLog\AbstractHandler->log() in src/XF/ModeratorLog/AbstractHandler.php at line 47
XF\ModeratorLog\AbstractHandler->logChange() in src/XF/ModeratorLog/Logger.php at line 62
XF\ModeratorLog\Logger->logChanges() in src/XF/Logger.php at line 47
XF\Logger->logModeratorChanges() in src/XF/Entity/Post.php at line 502
XF\Entity\Post->_postSave() in src/XF/Mvc/Entity/Entity.php at line 1137
XF\Mvc\Entity\Entity->save() in src/XF/Service/Post/Editor.php at line 165
XF\Service\Post\Editor->_save() in src/XF/Service/ValidateAndSavableTrait.php at line 40
XF\Service\Post\Editor->save() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 59
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13
 
Has anyone figured out how to properly replace <br> and <br /> with this? I'm cleaning up old html and this was mentioned as problematic in this thread but no solution posted.
 
For anyone having problems matching strings that span multiple lines, you need to use the s switch on your regex to allow this to work.

For example, a reflex to find the following:

Rich (BB code):
[quote]
[B]Originally posted by Someone[/B]

Would look like this:

Code:
/\[quote\]\s*\[b\]originally posted by (.+)\[/b\]/siU
Note that I’m using a case-insentitive (i), multi-line (s) regex that is also ungreedy (U), so it will stop matching at the first [/b] that it comes across.[/quote]
 
Oh man @Kier that is a huge help, I only wish I knew that when I was performing my DNN > XF conversion so I didnt' have to dump everything to an excel spreadsheet and do it all manually (sort of....used DigDB)

I can still find a use for this though I think, great hint
 
Not quite... instead of a line break I get text "\n" inserted in posts.
Tested on local and it works.

Don't forget to backup the table first for safety reason ;)
Or you may test on test forum installation first.
Code:
UPDATE xf_post
SET message = REPLACE(message, '<br>', '\n');

UPDATE xf_post
SET message = REPLACE(message, '<br/>', '\n');

UPDATE xf_post
SET message = REPLACE(message, '<br />', '\n');
 
Top Bottom