Find and Replace Using Regular Expressions and Capture Groups In Sublime Text

I recently needed to perform a refactor which involved re-namespacing several classes (where several is more like a shit tonne). I've had to do this before and was not looking forward to the mind numbing manual task ahead.

I know just enough regex to know that I don't know regex, and I have played with capture groups before (...Splunk...). I've known about the regex search function in Sublime Text for a while, but was not game enough to try regex find and replace. Until now!

So, lets say I have one "shit tonne" of classes all under the Example namespace:


And I want to move all these classes into the Contrived namespace:

Example::Shit  => Contrived::Example::Shit
Example::Tonne => Contrived::Example::Tonne

Here's the (find with regex) magic:

Find: (Example::[a-zA-Z]*)
Replace: Contrived::$1