更新时间:2023-12-04 13:40:16
我相信像这样的正则表达式应该可以工作:
I believe a regex like this should work:
^(\h*)logging\.info\(([^)]*)\)
替换为:
$0\n$1print($2)
说明:
^ # 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