我有一个python脚本:如何使用Ruby正则表达式来搜索路径并将其替换?
speaking_to_sublime.py
import sublime, sublime_plugin
class SpeakingToSublime(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("advanced_new_file_new",{"initial_path": "/Users/max/test/test2/"})
,我试图写一个Ruby脚本,执行以下操作:
desired_path = "/some/path/i/want/to/go/"
# read speaking_to_sublime.py
# parse through it and store as a string
# store contents of speaking_to_sublime.py in here
speaking_to_sublime_string = ""
# use regular expressions to somehow replace:
# "/Users/max/test/test2/" with desired_path
# write speak_to_sublime_string to speaking_to_sublime.py
我能想出如何使用ruby读写文件,但是如何使用正则表达式来获取"/Users/max/test/test2/"
并将其替换为"/some/path/i/want/to/go/"
?
为什么不只是将Python脚本更改为接受路径参数? –