44

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 ?

davidcondrey
  • 34,416
  • 17
  • 114
  • 136
Alex
  • 66,732
  • 177
  • 439
  • 641

1 Answers1

49

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:

AlliterativeAlice
  • 11,841
  • 9
  • 52
  • 69
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 2
    Sublime text 3 does not take regex in the "Replace With" field. If I put a regex there, it just dumps that regex as string in the editor. How can I use regex in "Replace" field in sublime? Basically, I want to search all words (basically hex colour values) beginning with "#" and add some string before and after that word. Using "\#\w+", I can find all such words, but if I do string1\#\w+string2, it outputs it as it is, without replacing regex with actual word. – darKnight Apr 01 '16 at 10:43
  • 2
    @dk49: Use as below: Find: (#\w+) Replace: text-before\1text-after – Mahesh Sep 28 '16 at 07:04