崇高的文本查找、复制、更改和粘贴到新行 [英] sublime text find, copy, change and paste in new line

查看:28
本文介绍了崇高的文本查找、复制、更改和粘贴到新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来查找文档中的特定文本并更改并粘贴到新行中.

I need a Regex to find the certain text in document and change and paste in new line.

logging.info("hello i am here")

需要找到所有出现的logging.info并改成

need to find all occurrence of logging.info and change to

print("hello i am here")

最终看起来像这样

logging.info("hello i am here")
print("hello i am here")

他们的正则表达式是我可以做的还是我需要手动做的.

Is their any regex that i can do or i need to do manually.

推荐答案

我相信像这样的正则表达式应该可以工作:

I believe a regex like this should work:

^(\h*)logging\.info\(([^)]*)\)

替换为:

$0\n$1print($2)

regex101 演示

说明:

^                 # Beginning of line
(\h*)             # Get any spaces/tabs before the line and store in $1
logging\.info\(   # Match 'logging.info('
([^)]*)           # Get everything between parens
\)                # Match closing paren

请注意,上述正则表达式假定 logging.info 函数中没有其他括号.

Note that the above regex assumes there are no other parens within the logging.info function.

替换意味着:

$0                # Whole match
\n                # Newline
$1                # Place the indentation
print(            # 'print('
$2                # The part within the `logging.info` function
)                 # Closing paren

这篇关于崇高的文本查找、复制、更改和粘贴到新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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