Original article explanation is here:
http://www.kirstencassidy.com/cleaning-up-formatting-shortcodes/
\[/vc(.*?)\]
\[vc(.*?)\]
\[custom_font(.*?)\]
\[/custom_font(.*?)\]
\[/vc_column_text(.*?)\]
\[vc_separator(.*?)\]
<hr>
\[/vc_column(.*?)\]
\[vc_row(.*?)\]
\[portfolio_list(.*?)\]
Finding shortcodes in general
(?!\[CDATA\[)\[(.*?)\]
Keeping some elements
(?!\[vc_single_image(.*?)\])(\[vc(.*?)\])
Step 1
// Remove Visual Composer Stuff Except Images
(?!\[vc_single_image(.*?)\])(\[vc(.*?)\])
\[/vc(.*?)\]
Step 2
// Remove Custom Fonts
\[custom_font(.*?)\]
\[/custom_font(.*?)\]
Step 3
# Change Visual Composer Images To...Actual Images
# Regex ID ONLY - Don't use - just to find IDs
$ (?<=\[vc_single_image image=")([0-9]*)(?=")
# WHOLE SHORTCODE
$ (\[vc_single_image image=")([0-9]*)(?=")(.*\])
# alternative
$ (\[vc_single_image(.*)image=")([0-9]*)(?=")(.*\])
# Replace with
$ <PanelImage>$2</PanelImage>
Step 4
# Add more XML Elements
# Find end of Content (use whatever element you like)
$ </Element>
$ </Element>\n\t\t<NewElement>\n\t\t</Panels>
** Other Helpers **
# Replace vc_video link with plain video
$ (\[vc_video link=['|"])([a-zA-Z://.?=_0-9]*)(['|"])(\])
with
$ $2
http://www.themelab.com/put-shortcodes-in-a-plugin/
When a user changes themes, it can be a pain to go through the site's content and fix any of the shortcodes. Maybe a shortcode was not required in the first place, and this can be changed with regular html - eg a button can simply be changed from:
[button]Foo[/button]
to
<button>Foo</button>
Any styling associated with the theme will correctly be applied to the html.
For example, if a shortcode is already used site wide, it will be easier to keep the shortcode and retain the functionality.
Therefore extract the shortcode, and place it inside a plugin that can be used regardless of changes in themes at a later date.
An example would be:
[latest_post type="foo" number_of_columns="foo"]
If this is used in multiple places, simply create a plugin. Obviously, it would be better for the plugin to style it, however it's permissible for the theme to style it correctly.
Regex Helper
https://gist.github.com/gemmadlou/7a0189bfae6c2c7268de12f1de822b8a
Thanks for sharing this tutorial, I developed a free plugin named ( Shortcode Cleaner Lite ), to solve this exact problem.
https://wordpress.org/plugins/shortcode-cleaner-lite
Video demo: https://www.youtube.com/watch?v=dXVZ5bSUduc
It will Clean your WordPress content from any unused broken shortcodes, which it clean up unused, broken shortcodes from WordPress content automatically, so you can switch between themes and plugins without worrying and keep your content cleanly and fresh all the time, it is dealing with any theme (Divi, Avada..etc) shortcodes that are left when changing themes or plugins or page builders (Visual Composer, Elementor, Beaver…etc).
I hope it will be useful.