正则表达式替换包含 sublime 中替换部分匹配的值? [英] Regex to replace values that include part of match in replacement in sublime?

查看:27
本文介绍了正则表达式替换包含 sublime 中替换部分匹配的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出了这个正则表达式来查找所有以 $ 开头并包含 _ 下划线的单词:

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

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

我基本上是在寻找变量,比如 $var_foo

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

如何使用正则表达式组替换内容?

How do I replace stuff using the regex groups?

例如,如何删除下划线并使下一个字母大写,例如 $varFoo ?

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

推荐答案

替换表达式为:

\$\1\u\2

  • \1, \2 是捕获(或 $1, $2)
  • \u up-cases(参见替换字符串语法部分).
    • \1, \2 are the captures (or $1, $2)
    • \u up-cases (see the Replacement String Syntax section).
    • 请参阅正则表达式章节 (在TextMate 文档) 了解更多信息.

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

      已经有一个包可以做到这一点,还有更多:

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

      这篇关于正则表达式替换包含 sublime 中替换部分匹配的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆