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
  • 29,530
  • 14
  • 105
  • 129
Alex
  • 60,472
  • 154
  • 401
  • 592

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
  • 9,983
  • 8
  • 41
  • 65
Dave Newton
  • 152,765
  • 23
  • 240
  • 286
  • 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