Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ini_regexen_dicts.py
- import re
- delims = { 'sect open': r"\[",
- 'sect close': r"\]",
- 'option': r"=",
- 'comment': r";",
- }
- regexen = { 'section':
- r"""
- ^%(sect open)s
- ([^%(sect open)s%(sect close)s%(comment)s%(option)s]+)
- %(sect close)s
- """ % delims,
- 'option':
- r"""
- ^
- ([^%(option)s%(sect open)s%(sect close)s%(comment)s]+)
- %(option)s
- """ % delims,
- 'setting':
- r"""
- %(option)s
- ([^%(comment)s]*)
- %(comment)s?
- """ % delims,
- 'comment':
- r"""
- %(comment)s
- (.*)
- """ % delims,
- 'other':
- r"""
- ^
- ([^%(sect open)s%(sect close)s%(comment)s%(option)s]*)
- $
- """ % delims,
- }
- patterns = dict((name,re.compile(regex, re.VERBOSE))
- for name,regex in regexen.iteritems())
Advertisement
Add Comment
Please, Sign In to add comment