/ svn-cassiopeia --username yuuma.tomita@gmail.com/cas_helper/xldb/utils/re_tools/re_test.py
Python | 80 lines | 79 code | 1 blank | 0 comment | 0 complexity | 8e78d530865cf6dd7716bfe1fd7e5ab6 MD5 | raw file
- import re
-
- def repl_f():
- def rep(mo):
- return ''.join(mo.groups())
- return rep
-
- t='abcd'
- _re = re.compile(r'a(bc)d')
- _re.search(t).groups()
-
- _re.sub(r'\g<1>', t)
-
- _re.sub(repl_f(), t)
-
-
-
- import re, dateutil
- from xldb.sheetutils import get_named_tablib
- from xldb.utils.parsers.date_parser import date_normalize
- from xldb.utils.parsers.mapp import mapp
-
- re_flag = re.I|re.U|re.MULTILINE|re.DOTALL|re.VERBOSE
- d = get_named_tablib('jwits', 'odekake', u'???')
- whole = '\n'.join(d[u'??'])
-
- def replacer_factory(repl_exp=None): #m=match_object
- def replacer(mo):
- res = None
- if mo:
- items = [item.replace('\r', '').replace('\n', '') for item in mo.groups() if item ]
- res = ' '.join(items)
- return res
- return replacer
-
- def replacer(mo):
- res = None
- if mo:
- items = [item for item in mo.groups() if item ]
- res = ' '.join(items)
- return 'replacer'
-
-
- main_exp = ur"""
- .+??????(?????????????????|[\s]*)[\s]*(?P<M>.+?)[\s]+[=]{4,}.+
- """; main_re = re.compile(main_exp, re_flag)
- print u'<{0}>'.format(main_re.sub(r'\g<M>', whole)[0:100])
-
- #.+??????(?????????????????|[\s]*)[\s]*(?P<M>.+?)[\s]+??????.+
-
- tt = u"""
- ???????????????
- ???????
- ???????????????????????
- ??????????????5.5?H? ?????????6.0?H?
-
- ???????23?3?17?????AM??PM14?00
- -----------------------------------------------------------------------------------
- """
-
- main_exp = ur"""
- .+^????[^?]+?[^\d]+([\d.]+).+
- """; main_re = re.compile(main_exp, re_flag)
- print u'<{0}>'.format(main_re.sub(r'\g<1>', tt)[0:100])
-
- #.+^????[?\s]+[^?]+?([^\n?]+?)[\s]*[\n].+
-
- print main_re.match(whole).groups()[0]
- print main_re.sub(replacer, tt)
-
- print main_re.sub(replacer, whole)
- print main_re.sub(r'\g<1>', whole)[0:300]
-
- main_rep = None
-
-
- main_value = main_re.sub(replacer_factory(main_rep), whole)
-
- main_re.sub(r'abc', whole)
-