Resource icon

Post Content Find / Replace 1.0.0

No permission to download
mhm. I keep getting time outs as there are 13k results. So I will need to split it up. Attached are the font codes I have.

With the previous replacement I got the error that I needed to fill in a replacement text. But I just want to remove it. Is there anything I can fill in the replacement field to avoid that?

You can break the job up using more precise matching.

In some cases sure but not all. Jake Bunce posted a fix for this a long time ago which allows you to batch things without accounting for more unique signatures with your regex.

If you are comfortable making a few edits you can follow this post and set your offsets in the script,
https://xenforo.com/community/threads/import-from-ipb-3-2-posts-not-parsed-at-all.39577/#post-435226

If you would like to play with those offsets and not keep editing the script every time you would like to change offsets you can follow this edit which is the same thing except once done the options will be added to the addon ending the need for further edits,
https://xenforo.com/community/threads/post-content-find-replace.6548/page-53#post-1019961
 
Code:
#(\[img]https://www\.my\-forum\.com)/forum/attachment\.php\?attachmentid=([0-9]+)&d=([0-9]+)(\[/i m g])#siu

looks like it wants to match something like

Code:
[IMG]https://www.my-forum.com/forum/attachment.php?attachmentid=123&d=222[/img]

What's that "d=(some number)" do? Do you need it for anything? Find an oldvB link and see if attachmentid and d are the same number
 
Last edited:
I tried

Code:
\[img\](https:\/\/www\.my-forum\.com)\/forum\/attachment\.php\?attachmentid=([0-9]+).*\[\/img]


for

Code:
[IMG]https://www.my-forum.com/forum/attachment.php?attachmentid=123&d=222[/IMG]

Try it out in http://regexr.com with your actual forum url. Remember to set all flags


The replacement would be

Code:
[img]\1/attachments/\2[/img]

This is a case where you can do some real damage if you don't have the replace done right. Please take precautions!
 
This results in a server error:
Server Error

preg_match_all(): Delimiter must not be alphanumeric or backslash
 
Whenever you are writing a regex you need to backslash the following / \ . [ ] ? . ^ * and some others (look up regex escaping specail characters)

In PHP you can use other delimiter characters besides / and /, such as # and #. I always use slashes so I can test it in a JavaScript driven regex tester
 
This results in a server error:
Server Error

preg_match_all(): Delimiter must not be alphanumeric or backslash
Oh, when I copied the regex from the tester it left out the delimiters (/ and /)

Code:
/\[img\](https:\/\/www\.my-forum\.com)\/forum\/attachment\.php\?attachmentid=([0-9]+).*\[\/img]/i
 
Code:
/\[img\](https:\/\/www\.my-forum\.com)\/forum\/attachment\.php\?attachmentid=([0-9]+).*?\[\/img\]/i

This is a little safer. The "?" near the end makes sure it finds the shortest possible match. Sometimes regexes overmatch and grab more than you want.
 
I've read a lot but did not find a solution for this, although I would expect it as very common.

How do I find and replace such media includes with title or URL, please?
This may occour for YouTube and Vimeo and with mixed character cases:

Code:
[YOUTUBE="This is the title of the video"]on8EBjTftcg[/YOUTUBE]
[YOUTUBE="https://www.youtube.com/watch?v=on8EBjTftcg"]on8EBjTftcg[/YOUTUBE]

[VIMEO="This is the title of the video"]236410761[/VIMEO]
[VIMEO="https://vimeo.com/236410761"]236410761[/VIMEO]

Thank you for any help.
 
Find: /\[youtube=[^\]]+\]([\S\s]+?)\[\/youtube\]/i
Replace: [MEDIA=YOUTUBE]\1[/MEDIA]


Find: /\[vimeo=[^\]]+\]([\S\s]+?)\[\/vimeo\]/i
Replace: [MEDIA=VIMEO]\1[/VIMEO]

 
I think this will get them all in one fell swoop

Find: /\[(YOUTUBE|VIMEO)=[^\]]+?\]([^\[]+?)\[\/(YOUTUBE|VIMEO)\]/i

Replace: [MEDIA=\1]\2[/MEDIA]
 
Last edited:
Thank you so much, @Nerbert. Will try in the next hour. Is this case sensitive? Anyway, I'll try and can run it with lower cases a second time!
 
I did something slightly wrong with an SQL-query and now transfered the end of the youtube embeded already.

So, the query (forget to simulate before ******, yes I have an update but want to avoid that) was:
Code:
UPDATE xf_post SET message = REPLACE(message, '[/youtube]', '[/MEDIA]');

Will this work (I really have no clue from regex)?

Code:
Find: /\[youtube=[^\]]+\]([\S\s]+?)/i
Replace: [MEDIA=YOUTUBE]\1

edit: I probably just could revert it ;)
Code:
UPDATE xf_post SET message = REPLACE(message, '[/MEDIA]', '[/youtube]');

But, the addon gave me an error 500 with this one, just simualting (not saving):

Code:
Find: /\[youtube=[^\]]+\]([\S\s]+?)/i
Replace: [MEDIA=YOUTUBE]\1

Is this faulty or does my AWS instance does not manage to replace that?

And: does you full query work for titles with and without quote marks ""?
 
Last edited:
Top Bottom