This is a very simple add-on I put together in order to allow an administrator to do a regular expression find and replace in the content of all posts.
It was written in order to find all instances of a custom BB code tag for embedding YouTube video in an imported posts, and convert them to XenForo's [media=youtube] tag automatically.
The interface is simple - you have three text fields and a checkbox.
The first is a simple text search, which helps to narrow down the number of posts that will be searched with the regular expression.
The second field should contain a full and valid PCRE regular expression, including flags and terminators.
The third field will be used to determine the replacement text.
The checkbox is used to switch between testing and commit mode. Unchecked, the replacements will be displayed but not saved.
Example usage to convert from [video="http://www.youtube.com/watch?v=ZSW4LDAHIeU"]Video title here[/video] to [media=youtube]ZSW4LDAHIeU[/media]:
Quick Find:
Regular Expression:
Replacement String:
Limitations:
Enjoy.
Edit: Jan 10th 2011 - Code updated and fixed. Not sure how I missed that but... oh well. Thanks to whyweprotest for spotting my silly error.
It was written in order to find all instances of a custom BB code tag for embedding YouTube video in an imported posts, and convert them to XenForo's [media=youtube] tag automatically.
The interface is simple - you have three text fields and a checkbox.
The first is a simple text search, which helps to narrow down the number of posts that will be searched with the regular expression.
The second field should contain a full and valid PCRE regular expression, including flags and terminators.
The third field will be used to determine the replacement text.
The checkbox is used to switch between testing and commit mode. Unchecked, the replacements will be displayed but not saved.
Example usage to convert from [video="http://www.youtube.com/watch?v=ZSW4LDAHIeU"]Video title here[/video] to [media=youtube]ZSW4LDAHIeU[/media]:
Quick Find:
[video
Regular Expression:
#\[video=youtube;([^\]]+)\]([^\[]+)\[/video\]#siU
Replacement String:
[media=youtube]\1[/media]
Limitations:
- The system will not check that your regular expression is valid, or that it matches. It will fall over if your expression does not compile, and it will simply not match anything if the logic is incorrect.
- There is no batch processing in this add-on, so if you are replacing something that occurs in a lot of posts, this could be very slow and might time-out.
Enjoy.
Edit: Jan 10th 2011 - Code updated and fixed. Not sure how I missed that but... oh well. Thanks to whyweprotest for spotting my silly error.