Skip to content

Instantly share code, notes, and snippets.

@satabin
Created February 4, 2016 16:13
Show Gist options
  • Select an option

  • Save satabin/806738208a4489396200 to your computer and use it in GitHub Desktop.

Select an option

Save satabin/806738208a4489396200 to your computer and use it in GitHub Desktop.
def check(before, pattern, after):
import re
if before:
before = '(?<=%s)' % before
else:
before = ''
if after:
after = '(?=%s)' % after
else:
after = ''
regex = re.compile('^((?!%s).|%s%s%s)*$' % (pattern, before, pattern, after))
return regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment