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

核能气质少年 提交于 2019-12-03 05:30:41

问题


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 ?


回答1:


The replacement expression is:

\$\1\u\2
  • \1, \2 are the captures (or $1, $2)
  • \u up-cases (see the Replacement String Syntax section).

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

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

  • Brief blog about CaseConversion
  • CaseConversion package


来源:https://stackoverflow.com/questions/10841060/regex-to-replace-values-that-include-part-of-match-in-replacement-in-sublime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!