Resource icon

Post Content Find / Replace 1.0.0

No permission to download
I have a bunch of old [video] tags which I believe are remnants left over from when the forum was running phpBB before vBulletin. I used the vB video find and replace string but I still have a bunch of video tags like this that pre-date vB:

Code:
[video]http://www.youtube.com/v/qRuNxHqwazs&hl=en&fs=1&rel=0[/video]

Would anyone be so kind as to set me up with the regex I need to convert these?
 
Code:
[video]http://www.youtube.com/v/qRuNxHqwazs&hl=en&fs=1&rel=0[/video]



Quick Find:
Code:
[video


Regular expression:
Code:
#(?:\[video])http(?:s)?://(?:www\.)?(?:[a-z0-9-]+\.)?youtu(?:be\.com/(?:[a-z]+(?:/api/videos/)?)|\.be)(?:\?v=|/)?([a-z0-9_-]{11})(?:[^\s]+)?(?:\[/video])#siu


Replacement String:
Code:
[media=youtube]\1[/media]
 
Quick Find:
Code:
[video


Regular expression:
Code:
#(?:\[video])http(?:s)?://(?:www\.)?(?:[a-z0-9-]+\.)?youtu(?:be\.com/(?:[a-z]+(?:/api/videos/)?)|\.be)(?:\?v=|/)?([a-z0-9_-]{11})(?:[^\s]+)?(?:\[/video])#siu


Replacement String:
Code:
[media=youtube]\1[/media]

Thank you! Worked perfectly.
 
1. I've got a few thousand image links that are all dead links. They are all of the following format:
Code:
http://184.72.239.143/mu/randomnumber.jpg

These are all wrapped in image tags. How do I use the tool to find them all and delete them. It would more a removal of broken images.

Thanks. Excited about this tool as I've got 2400 of these.

2. I've got a ton of broken image links from gallery pages from old mac.com sites.

They are all of the format:
Code:
http://gallery.mac.com/username/
http://idisk.mac.com/username/
http://homepage.mac.com/username/

They have various different strings at the ends of their URLs.

3. Due to legal issues a few years back, I was forced to change my domain. I still have links to the old site, which don't resolve. How can I change domain.com/forum/thread.123 to newdomain.com/forum/thread.123
 
Last edited:
How would you use this to change all none youtube links. Basically I would like to convert all non youtube links into a URL.

From:
Code:
[ame=www.SomeLongWesbitesiteURL.com(or another extension)]A description of the site[/ame]

T0:
Code:
[URL='http://www.SomeLongWesbitesiteURLcom(or another extension)']A description of the site[/URL]


Since I dont know the name of site im looking for, I just want to find all site that do not have youtube in the name.

Thanks!
 

Quick Find:
Code:
v6mustang.com/threads


Regular expression:
Code:
#(\[url(?:]|[^]]+]))(http://www\.v6mustang\.com/threads/[0-9]+/)[^\[]+(\[/url])#siu


Replacement String:
Code:
[url]\2[/url]



__________________________________________________




dead image links links

format:
Code:
http://184.72.239.143/mu/randomnumber.jpg

find them all and delete them.

Quick Find:
Code:
184.72.239.143


Regular expression:
Code:
#(\[img]http://(?:www\.)?184\.72\.239\.143/mu/[a-z0-9-]+\.(?:jpg|jpeg|png|gif|bmp|tif)\[/img])#siu


Replacement String:
Code:
IMAGE-REMOVED


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


2. broken image links

They are all of the format:
Code:
http://gallery.mac.com/username/
http://idisk.mac.com/username/
http://homepage.mac.com/username/

They have various different strings at the ends of their URLs.
Those various strings are important and necessary in order to do anything about it.

find one of those links in a post, while logged in as an admin/mod edit the post and then click the icon to the right for 'use bbcode editor ' and then copy the contents for one of the links tags and all and then paste them into a code block here.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

3. change domain.com/forum/thread.123 to newdomain.com/forum/thread.123


Quick Find:
Code:
domain


Regular expression:
Code:
#domain(\.com/forum/thread\.[0-9]+[^\s]+)#siu


Replacement String:
Code:
newdomain\1



__________________________________________________



How would you use this to change all none youtube links. Basically I would like to convert all non youtube links into a URL.

From:
Code:
[ame=www.SomeLongWesbitesiteURL.com(or another extension)]A description of the site[/ame]

T0:
Code:
[URL='http://www.SomeLongWesbitesiteURLcom(or another extension)']A description of the site[/URL]


Since I dont know the name of site im looking for, I just want to find all site that do not have youtube in the name.

Thanks!
that's not enough information for me, I refer to what I told the gent above...

find one of those links in a post, while logged in as an admin/mod edit the post and then click the icon to the right for 'use bbcode editor ' and then copy the contents for one of the links tags and all and then paste them into a code block here.
go to one of the posts that has an ame link that is not youtube and follow the above process so that I can get a better picture of what needs to be done.
 
Last edited:
that's not enough information for me, I refer to what I told the gent above...


go to one of the posts that has an ame link that is not youtube and follow the above process so that I can get a better picture of what needs to be done.

Thanks for looking into this:

Basically there are too many different urls to list but the idea is just to replace the "[ame=" with "[U RL=" and "[/ame]" with "[/ U RL]"
[CODE]
- [ame="http://en.wikipedia.org/wiki/Bulletin_board_system"]Tigger BBS[/ame]
- [ame="http://en.wikipedia.org/wiki/Honda"]Honda[/ame]
- [ame="http://www.vimeo.com/12833600"]Four Wars 3-5-12 on Vimeo[/ame]
- [ame="http://s64.photobucket.com/albums/h170/crawlertypeofguy/?action=view&current=DSCF2215.flv"]DSCF1215.flv video by crawlertypeofguy - Photobucket[/ame]
- [ame="http://video.google.com/videoplay?docid=8769128457543333500&q=winchester+bay&total=71&start=0&num=10&so=0&type=search&plindex=4"]YouTube - Banshee Bay Oregon[/ame]
[/CODE]
It woudl be quite easy to maybe do this regex "#\[ame\=(.+)\[\/ame\]#siu" but that would destroy the working youtube video urls if this is run while there are still some video urls left. Can something be added to the above short regex to exclude if it contains "youtube" anywhere between the ame tags?

Also, I used a great code you provided some posts earlier and slightly modified it to include all possible subdomian (www, m, de, ca, etc.. ), possibility of having quotes around url and the secure version of youtube urls (https):

From:
Code:
#\[ame\=http\:\/\/(www\.)?youtube.com\/watch\?([a-z]+\=[^\=\&\]]+\&)*v\=([^\]\&]+)(\&[a-z]+\=[^\=\&\]]+)*\][^\[]+\[\/ame\]#siu

To:
Code:
#\[ame\=('|"|)http(s)?\:\/\/[^\.]*(\.)?youtube.com\/watch\?([a-z]+\=[^\=\&\]]+\&)*v\=([^\]\&\"]+)(\&[a-z]+\=[^\=\&\]]+)*('|"|)?\][^\[]+\[\/ame\]#siu

After this update I still ran into a few issues where the following domain were not affected because either the Description was left blank or the description contained brackets:
Code:
- [ame=http://www.youtube.com/watch?v=XjiwBwBL4Qo]YouTube - Classified - "Oh... Canada" [Official Video][/ame]
- [ame="http://www.youtube.com/watch?v=RboEtvkm4RU"][COLOR=#0000ff]YouTube- ATV's Most Wanted Susan Parker[/COLOR][/ame]
- [ame="http://www.youtube.com/watch?v=SZq8WppNFJY"][COLOR=yellow]http://www.youtube.com/watch?v=SZq8WppNFJY[/COLOR][/ame]
- [ame="http://www.youtube.com/watch?v=sWEKU9fEBno"][/ame]
- [ame="http://www.youtube.com/watch?v=9YAPKlk0pfY&feature=related="]YouTube - le burn a la marocaine[/ame]

Any idea on how to modify the above regex to include those or would it be better to just write a separate one for the select few cases?
 
Quick Find:
Code:
184.72.239.143


Regular expression:
Code:
#(\[img]http://(?:www\.)?184\.72\.239\.143/mu/[a-z0-9]+\.(?:jpg|jpeg|png|gif|bmp|tif)\[/img])#siu


Replacement String:
Code:

When I run it, nothing happens. It remains the post and replace screen, as if it's not able to find anything.

Here's an example of the BBD code associated with the assorted images.

Code:
[IMG]http://184.72.239.143/mu/ad314e39-3ae3-9271.jpg[/IMG]

Those various strings are important and necessary in order to do anything about it.

find one of those links in a post, while logged in as an admin/mod edit the post and then click the icon to the right for 'use bbcode editor ' and then copy the contents for one of the links tags and all and then paste them into a code block here.

Here are a few of the BBCodes for those broken image URLs, most caused by Mac.com closing.

Code:
[IMG]http://idisk.me.com/scottjf8/Public/Pictures/Skitch/DSC_0002-20090512-151409.jpg[/IMG]

[IMG]http://gallery.mac.com/kings05/100008/photo1231443152669/web.jpg[/IMG][/QUOTE]

Thanks, I greatly appreciate your help. Having just found a lot of these links today, I'm anxious to get my site cleaned up.
 
This is why I ask for the EXACT examples from the bbcode editor view of a post containing the content copied and pasted here..

above you asked for
http://184.72.239.143/mu/randomnumber.jpg

but it in no way tells me that it will have an alpha numeric string with dashes in it after the last slash.
http://184.72.239.143/mu/ad314e39-3ae3-9271.jpg

I have edited the above post to reflect that, try it now.



I just got out of bed and need coffee, I'll be back later.
 
Great addon, I just discovered this problem a week after migration from vB4 (once I fixed the FF and https issue)

So before I actually execute anything, 1) going to turn off the board and do a full backup and 2) I want to make sure I have the coding right.

I have ran across a few scenarios on my existing board (which is not large yet)

I need to convert the following situations:

#1
Code:
[video=youtube;xj0SF_V4C_U]https://www.youtube.com/watch?v=xj0SF_V4C_U[/video]

Fix for #1

Code:
Quick Find: [video=youtube;
Regular expression: #\[video=youtube\;([a-z0-9]+)\]http.+\/watch.+v=[a-z0-9]+\[\/video\]#siu
Replacement String: [media=youtube]\1[/media]


#2
Code:
[video=youtube_share;0yU2sxineQQ]http://youtu.be/0yU2sxineQQ[/video]

Fix for #2

Code:
Quick Find: [video=youtube_share;
Regular expression: #\[video=youtube_share\;([a-z0-9]+)\]http.+\/watch.+v=[a-z0-9]+\[\/video\]#siu
Replacement String: [media=youtube]\1[/media]

#3
Code:
[URL]http://youtu.be/p-h4VVRMj5A[/URL]

Fix for #3?

This one gets cleanly fixed when I simply Edit and Save the post. The others do not as they leave a hanging video=youtube text preceeding the video. But I don't want to have to go find and edit every post with a URL youtube link.

Thanks ahead of time
 
This is why I ask for the EXACT examples from the bbcode editor view of a post containing the content copied and pasted here..

above you asked for
http://184.72.239.143/mu/randomnumber.jpg

but it in no way tells me that it will have an alpha numeric string with dashes in it after the last slash.
http://184.72.239.143/mu/ad314e39-3ae3-9271.jpg

I have edited the above post to reflect that, try it now.



I just got out of bed and need coffee, I'll be back later.

It generated the list, which was great. When I select save changes either before or after creating the list, it kicks back the error code - Please enter a valid message. I tried adding a space or two, but no change.

Thanks again. If I can delete 1900 broken image links, this would make my day -- better yet, my week!
 
I need to convert the following situations:

#1
Code:
[video=youtube;xj0SF_V4C_U]https://www.youtube.com/watch?v=xj0SF_V4C_U[/video]

Fix for #1

Code:
Quick Find: [video=youtube;
Regular expression: #\[video=youtube\;([a-z0-9]+)\]http.+\/watch.+v=[a-z0-9]+\[\/video\]#siu
Replacement String: [media=youtube]\1[/media]

...ok being a newbie here I didn't notice the Save Changes checkbox that you can leave unchecked and just test this type of stuff. I should have figured that this would have been incorporated!!

I did find that I have some posts that have multiple links in the same post, and the addon treats these as a single video. For instance, it wants to replace

Code:
     [video=youtube;Lalx66vIAl4]http://www.youtube.com/watch?v=Lalx66vIAl4[/video] [video=youtube;JNwnwdAV8wI]http://www.youtube.com/watch?v=JNwnwdAV8wI[/video] [video=youtube;j2-FsaNufL4]http://www.youtube.com/watch?v=j2-FsaNufL4[/video] [video=youtube;UTCJBnhYbnk]http://www.youtube.com/watch?v=UTCJBnhYbnk[/video]

with

Code:
[media=youtube]Lalx66vIAl4[/media]

For me, this is a simple thing, I can just fix the individual posts where this occurs and let the addon fix the rest. But I'm just curious how one would handle this otherwise, as I'm sure there are others out there with many more posts containing multiple links in a single post...
 
Seems that #1 and #2 don't work on links with this type of link

Code:
[video=youtube;saU-L4QcrEw]http://www.youtube.com/watch?v=saU-L4QcrEw[/video]

I presume that hypens and underscores are the issue. I found lots of these
 
It generated the list, which was great. When I select save changes either before or after creating the list, it kicks back the error code - Please enter a valid message. I tried adding a space or two, but no change.

Thanks again. If I can delete 1900 broken image links, this would make my day -- better yet, my week!
That happens because some of your posts have only that image in there...if you remove it and it is the only thing you have a blank post which you shouldn't be able to save anyways... if you place something in the replacement field like 'img-removed' it will save.





...ok being a newbie here I didn't notice the Save Changes checkbox that you can leave unchecked and just test this type of stuff. I should have figured that this would have been incorporated!!
Yeah it's like a safety thing...I mean to be honest most people shouldn't use this addon...not to say they shouldn't have it installed but most people don't really get regex and it can cause a SERIOUS problem with your post data if you do something wrong...and 99.9% of the time when dealing with regex...the problem will be user error. If you can pay someone to do replacements for you do so, otherwise be prepared to make a lot of backups.

I did find that I have some posts that have multiple links in the same post, and the addon treats these as a single video. For instance, it wants to replace

Code:
     [video=youtube;Lalx66vIAl4]http://www.youtube.com/watch?v=Lalx66vIAl4[/video] [video=youtube;JNwnwdAV8wI]http://www.youtube.com/watch?v=JNwnwdAV8wI[/video] [video=youtube;j2-FsaNufL4]http://www.youtube.com/watch?v=j2-FsaNufL4[/video] [video=youtube;UTCJBnhYbnk]http://www.youtube.com/watch?v=UTCJBnhYbnk[/video]

with

Code:
[media=youtube]Lalx66vIAl4[/media]

For me, this is a simple thing, I can just fix the individual posts where this occurs and let the addon fix the rest. But I'm just curious how one would handle this otherwise, as I'm sure there are others out there with many more posts containing multiple links in a single post...
(don't do that you are just going to make a mess and i'll explain why)
Your problem is in your regex and not the addon...the addon is a vessel you can use to basically do a preg_replace (php replacement) against your posts table...the quick find box is using mysql to find something in a given table and is used to limit what you are preg_replacing against to only posts that have the string from quick find in it...

While you are using a general .+ which will keep matching until it finds the last instance of things matching what is after the .+ which in essence could take a 10000 character post that starts and ends with a youtube video into a single media embed with no text...and it can do it to every post you have with a link using that expression.


You need to be specific with the expression and force a start and stop point for the expression and control as much as possible in between.

This will catch both example #1 and #2:

Quick Find:
Code:
[video=


Regular expression:
Code:
#(\[video=(youtube)[^]]+])http(?:s)?://(?:www\.)?(?:[a-z0-9-]+\.)?youtu(?:be\.com/(?:[a-z]+(?:/api/videos/)?)|\.be)(?:\?v=|/)?([a-z0-9_-]{11})(?:[^\s[]+)?(\[/video])#siu


Replacement String:
Code:
[media=\2]\3[/media]
 
Last edited:
Yeah dude, that was the bomb! It found everything!

I agree that it appears that this tool could be seriously dangerous in the wrong hands. Thus the reason why the preview option is so handy. You can not only see the code section that will be affected, you can also go right to the post and look at how it looks before anything is changed.

I ran the #1 preview and then just manually edited the posts with multiple links, ran the preview again, and everything looked good so I checked the box and ran it.

I ran yours and it found about 21 more bad links the previous one had not caught, including the ones with hyphens and underscores, and the youtube_share links too (which #2 did not catch, at all, because of the hyphens and underscores)

Thanks a ton man!

now, what about #3 in my first post, the URL links? These are a result of people copying & pasting links directly under the vB engine, which just get turned into hyperlinks. vB wasn't smart enough to recognize these and automatically turn them into embedded video. yet another reason why vB sucks and XF rocks. So I can manually find these and just edit the post and save it, but I was hoping the addon could at least find these instances for me.
 
#3
Code:
[URL]http://youtu.be/p-h4VVRMj5A[/URL]

Fix for #3?

This one gets cleanly fixed when I simply Edit and Save the post. The others do not as they leave a hanging video=youtube text preceeding the video. But I don't want to have to go find and edit every post with a URL youtube link.
Thanks ahead of time
Don't do that, it makes more work for whoever has to come up with the fixes, individually editing and saving posts is a last ditch effort always unless you are talking about a situation where you know something is only coming up ten times and you know the location and it isnt worth the time to come up with an expression to catch it.


untested (don't have time right now to test it) so test this first with save unchecked and I should remind you that you should always backup after you finish your import so that you can do this part without worrying on a test bed with your import data (which is what everyone should always be doing when following advice from someone they don't know that when followed can effect their entire site)

Quick Find:
Code:
[url


Regular expression:
Code:
#(\[url(?:]|[^]]+]))http(?:s)?://(?:www\.)?(?:[a-z0-9-]+\.)?youtu(?:be\.com/(?:[a-z]+(?:/api/videos/)?)|\.be)(?:\?v=|/)?([a-z0-9_-]{11})(?:[^\s[]+)?(\[/url])#siu


Replacement String:
Code:
[media=youtube]\2[/media]
 
Back
Top Bottom