Resource icon

Post Content Find / Replace 1.0.0

No permission to download
So another regex I'm searching for.
Regex to remove all [ img ] bbcode not enclosing a valid url?

Sample:
Code:
this is random post ..
and [img] random appear without an image.
random message then..
[/img] close tag appear

Try this for open tag:
Code:
/\[img\](?!((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?))/i

And this for closing tag:
Code:
/(?!((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?))\[\/img\]/i

don't check "Save Changes" until you make sure all results are valid. It hasn't been tested.
 
  • Like
Reactions: rdn
Can someone help me change this:

Code:
[IMG]http://www.example.com/forum/attachment.php?attachmentid=49056&d=1416873612[/IMG]

To this:
Code:
[IMG]http://www.example.com/xendev/attachments/ol41-jpg.49056/[/IMG]
Or this
Code:
 [IMG]http://www.example.com/xendev/attachments/49056/[/IMG]

Either seem to work fine in xenforo

I'm not sure what d=1416873612 in the first link is, but I don't think I need it.

Thanks!
 
Hello, Try this one:

Quick Find:
Code:
[IMG]http://www.example.com/forum/attachment.php?attachmentid

Regex:
Code:
#(\[img]http://www\.example\.com)/forum/attachment\.php\?attachmentid=([0-9]+)&d=([0-9]+)(\[/img])#siu

Replace:
Code:
\1/xendev/attachments/\2/\4

Always try first without saving.
 
Excellent! Thank you very much! I was able to use your lead to also modify a couple of other similar replacements I needed to make. Thanks again for the quick response!
 
...
Scroll down to what is now line (47) then find and highlight all of the following:
PHP:
                    $dw->setExistingData($post, true);

                    $dw->set('message', $message);
replace with the following:
PHP:
                    $dw->setExistingData($post, true);
                    if($input['silent']) { $dw->set('last_edit_date', 0);  }
                    $dw->set('message', $message);

...​

I'm having problems with the silent edit check box. When checked I still get Last edited by a moderator: 3 minutes ago on each message.

I made sure I did the replacement quoted above. Perhaps it's a permission issue for my admin account?
 
Fred, I know very little about regex expressions, but this seems to work:

Quickfind: https://example.com/register.php

Regular expression:
Code:
#https://example.com/register.php#siu

Replacement String:
Code:
https://example.com/login

You could also just run this query in phpmyadmin
Code:
UPDATE xf_post SET message = REPLACE(message, 'https://example.com/register.php', 'https://example.com/login');

None of this has been tested, so be sure to backup your database first.
 
This looked promising but I do not understand regular expressions. Isn't there a query that can just find and replace strings in the post table? If possible with multiple string replacement.

This is what I need:

Code:
FIND & REPLACE IN XENFORO DATABASE POST TABEL:

[IMG]http://forum.mydomain.com/images/rating/star1.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star2.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star3.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star4.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star5.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star6.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star7.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star8.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star9.png[/IMG]
[IMG]http://forum.mydomain.com/images/rating/star10.png[/IMG]

REPLACE WITH:

[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star1.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star2.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star3.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star4.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star5.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star6.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star7.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star8.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star9.png[/IMG]
[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/star10.png[/IMG]
 
Last edited:
You might be able to use
Code:
UPDATE xf_post SET message = REPLACE(message, '[IMG]http://forum.mydomain.com/images/rating/', '[IMG]http://forum.mydomain.nl/styles/default/mydomain.nl/review_rating/');

Be sure to back up your database first incase I'm wrong.
 
Does anybody have a list of replacements to run to convert most vb3.8 urls in posts to xenforo urls? How about vb4 urls to xenforo urls?

For example:
Convert this style of link
Code:
www.example.com/forum/showthread.php?t=4596
to
Code:
http://www.example.com/threads/4596/

And this
Code:
http://www.example.com/forum/profile.php?do=editoptions
to
Code:
http://www.example.com/account/preferences

I don't really have a problem figuring out most of the regex for these simple conversions (and some might be easier with a query), but a list of things to replace would save a lot of time.
 
Last edited:
Ok - I'm tried searching for this in this thread and have come up short.

Can anyone help me

FIND: [MENTION=5405]Todd[/MENTION]
REPLACE: @Todd

(no link or anything, just the text)

Thanks!
Todd
 
Does anybody have a list of replacements to run to convert most vb3.8 urls in posts to xenforo urls? How about vb4 urls to xenforo urls?

For example:
Convert this style of link
Code:
www.example.com/forum/showthread.php?t=4596
to
Code:
http://www.example.com/threads/4596/

And this
Code:
http://www.example.com/forum/profile.php?do=editoptions
to
Code:
http://www.example.com/account/preferences

I don't really have a problem figuring out most of the regex for these simple conversions (and some might be easier with a query), but a list of things to replace would save a lot of time.

For the first one u can use:
QF:
Code:
http://www.example.com/forum/showthread.php?t=
Regex:
Code:
#http://www.example.com/forum/showthread.php\?t=([0-9]+)#siu
Replace:
Code:
http://www.example.com/threads/\1

The second one is straight forward. U can figure that one out yourself. :)
 
For a mistake, there are too many of this in posts in my site:
Code:
[]
and also:
Code:
[manba- cheshmak]
How to replace them with a space?

Thanks
 
I've been trying for a couple of hours to try and fix some old content I've found on my site, but seems my regex building is just not strong enough and/or I'm not grasping it properly.
I'm trying to change;
Code:
[URL='http://[media=youtube]-wBH6HXidO4[/media]'][media=youtube]-wBH6HXidO4[/media][/URL]
into
Code:
[media=youtube]-wBH6HXidO4[/media]
Could anyone assist with the correct regex please?
 
I've been trying for a couple of hours to try and fix some old content I've found on my site, but seems my regex building is just not strong enough and/or I'm not grasping it properly.
I'm trying to change;
Code:
[URL='http://[media=youtube]-wBH6HXidO4[/media]'][media=youtube]-wBH6HXidO4[/media][/URL]
into
Code:
[media=youtube]-wBH6HXidO4[/media]
Could anyone assist with the correct regex please?

Try this (untested as of yet)

Quick Find:
Code:
[media=youtube]

Regular expression:
Code:
#\[URL='http://(\[media=youtube][a-z0-9_-]{11}\[/media])']\1\[/url]#siu

Replacement String:
Code:
\1
 
Top Bottom