Skip to content

Instantly share code, notes, and snippets.

@EliahKagan
Last active January 23, 2023 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EliahKagan/3d764c8099c7b652e1c2c01ee02dadaa to your computer and use it in GitHub Desktop.
Save EliahKagan/3d764c8099c7b652e1c2c01ee02dadaa to your computer and use it in GitHub Desktop.
code fence cleanup - finding broken code fences
#!/usr/bin/env python3
"""Expand (what's intended to be) a T-SQL expression for searching."""
def expand(text, pattern, replacement, min_count, max_count):
"""Expands \n and a single replacement with repetitions."""
for count in range(min_count, max_count + 1):
print(text.replace(pattern, replacement * count)
.replace(r'\n', "' + CHAR(10) + '")
.replace(r'\N', "' + CHAR(13) + CHAR(10) + '"))
if __name__ == '__main__':
expand(text=r"OR ph.Text LIKE '%\n```{}[^a-z\N]%'",
pattern=r'{}',
replacement=r'[^\N]',
min_count=0,
max_count=8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment