Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created February 12, 2009 22:45
Show Gist options
  • Save sneeu/62919 to your computer and use it in GitHub Desktop.
Save sneeu/62919 to your computer and use it in GitHub Desktop.
Replace several characters with ligatures.
# -*- coding: utf-8 -*-
import re
_REPLACEMENTS = (
('ffi\B', 'ffi', ),
('ff\B', 'ff', ),
('fi\B', 'fi', ),
('fl\B', 'fl', ),
)
def ligature(text):
for pattern, replacement in _REPLACEMENTS:
p = re.compile(pattern)
text = p.sub(replacement, text)
return text
if __name__ == '__main__':
import sys
lines = '\n'.join(sys.stdin.readlines())
print ligature(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment