View.find_all(pattern, <flags>, <format>, <extractions>) [Region]
Returns all (non-overlapping) regions matching the regex pattern. The optional flags parameter may be sublime.LITERAL, sublime.IGNORECASE, or the two ORed together. If a format string is given, then all matches will be formatted with the formatted string and placed into the extractions list.lstpos = view.find_all(pattern, <flags>, <format>, lstrepl)
for pos, repl in zip(lstpos, lstrepl):
view.replace(edit, pos, repl)castles_made_of_sand wrote:Remember, if you have a static list of regions, you should make modifications from the end of the buffer to the beginning, else you smash your offsets
lstpos = view.find_all(pattern, <flags>, <format>, lstrepl)
for pos, repl in reversed(zip(lstpos, lstrepl)):
view.replace(edit, pos, repl)import sublime, sublime_plugin
class PathUncToLocalCommand(sublime_plugin.TextCommand):
def run(self, edit):
RegionsResult = self.view.find_all("\\\\\S*\\([A-Z])\$", sublime.IGNORECASE)
print(RegionsResult)
# This is the string to find via regex
# \\computer7\C$\testdir\test.batRegionsResult = self.view.find_all(r"\\\\\S*\\([A-Z])\$", sublime.IGNORECASE)import sublime, sublime_plugin
class PathUncToLocalRegexReplaceExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
ListReplacements = []
RegionsResult = self.view.find_all(r"\\\\(\S)*\\([A-Z])\$", sublime.IGNORECASE, "\\2:", ListReplacements)
for i, thisregion in reversed(list(enumerate(RegionsResult))):
self.view.replace(edit, thisregion, ListReplacements[i])Users browsing this forum: No registered users and 3 guests