Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.33 KB

File metadata and controls

44 lines (35 loc) · 1.33 KB

Sublime text

Swap lines like that

- "name": docker.domain.tld
  "login": docker

Python

Python's re is painfully slow for replacements in relatively large (~900k) buffers. Use Google's RE2

pip3 install google-re2
import re2

options = re2.Options()
# [!!] Looks like posix_syntax is not needed. Tried it to make \S work. But looks it works by default
# # Without posix_syntax, perl_classes and one_line have no effect
# # https://github.com/google/re2/blob/6dcd83d60f7944926bfd308cc13979fc53dd69ca/re2/re2.h#L634
# options.posix_syntax = True
# # Enables (among others) \S
# options.perl_classes = True
# options.one_line = False

config, subs_num = re2.subn(pattern, replace, config, options=options)

for match in re2.finditer(pattern, config, options=options):
  pass