Regex to replace values that include part of match in replacement in sublime?

Alex picture Alex · May 31, 2012 · Viewed 26.7k times · Source

I've come up with this regex that finds all words that start with $ and contain _ underscores:

\$(\w+)_(\w+)

I'm basically searching for variables, like $var_foo etc.

How do I replace stuff using the regex groups?

For example, how can I remove the underscore and make the next letter uppercase, like $varFoo ?

Answer

Dave Newton picture Dave Newton · May 31, 2012

The replacement expression is:

\$\1\u\2

See the Regular Expressions chapter (in the TextMate docs) for more information.

There's already a package that does this, and more: