崇高文本查找,复制,更改和粘贴新行

时间:2014-05-09 06:22:36

标签: regex sublimetext3

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

logging.info("hello i am here")

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

print("hello i am here")

最终看起来像这样

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

他们可以做的任何正则表达式,或者我需要手动完成。

1 个答案:

答案 0 :(得分:6)

我相信像这样的正则表达式应该有效:

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

替换为:

$0\n$1print($2)

regex101 demo

说明

^                 # 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函数中没有其他parens。

替换意味着:

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