def tag_pattern2re_pattern(tag_pattern):
 tag_pattern = re.sub(u'\\s', u'', tag_pattern)
 tag_pattern = re.sub(u'<', u'(<(', tag_pattern)
 tag_pattern = re.sub(u'>', u')>)', tag_pattern)
 if (not CHUNK_TAG_PATTERN.match(tag_pattern)):
  raise ValueError((u'Bad tag pattern: %r' % tag_pattern))
 def reverse_str(str):
  lst = list(str)
  lst.reverse()
  return u''.join(lst)
 tc_rev = reverse_str(ChunkString.CHUNK_TAG_CHAR)
 reversed = reverse_str(tag_pattern)
 reversed = re.sub(u'\\.(?!\\\\(\\\\\\\\)*($|[^\\\\]))', tc_rev, reversed)
 tag_pattern = reverse_str(reversed)
 return tag_pattern

def tag_pattern2re_pattern ( tag_pattern ) : tag_pattern = re . sub ( u'\\s' , u'' , tag_pattern ) tag_pattern = re . sub ( u'<' , u'(<(' , tag_pattern ) tag_pattern = re . sub ( u'>' , u')>)' , tag_pattern ) if ( not CHUNK_TAG_PATTERN . match ( tag_pattern ) ) : raise ValueError ( ( u'Bad tag pattern: %r' % tag_pattern ) ) def reverse_str ( str ) : lst = list ( str ) lst . reverse ( ) return u'' . join ( lst ) tc_rev = reverse_str ( ChunkString . CHUNK_TAG_CHAR ) reversed = reverse_str ( tag_pattern ) reversed = re . sub ( u'\\.(?!\\\\(\\\\\\\\)*($|[^\\\\]))' , tc_rev , reversed ) tag_pattern = reverse_str ( reversed ) return tag_pattern
convert a tag pattern to a regular expression pattern .