当前位置: 首页>>代码示例>>Python>>正文


Python re.U属性代码示例

本文整理汇总了Python中re.U属性的典型用法代码示例。如果您正苦于以下问题:Python re.U属性的具体用法?Python re.U怎么用?Python re.U使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在re的用法示例。


在下文中一共展示了re.U属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_all

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def add_all(self, event):
        if self.frame.current_selection is not None:
            start = self.frame.charindex2position(self.frame.current_selection.lb)
            end = self.frame.charindex2position(self.frame.current_selection.ub)
        else:
            start, end = ("sel.first", "sel.last")
        try:
            target = re.escape(self.frame.text.get(start, end).strip())
            pattern = (u"\\b" if target[0].isalnum() else u"((?<=\\s)|(?<=^))") + target + (u"\\b" if target[-1].isalnum() else u"(?=\\s|$)")
            regex = re.compile(pattern, re.U + re.M)
            for match in regex.finditer(self.frame.doc.content):
                cur_start, cur_end = self.frame.charindex2position(match.start()), self.frame.charindex2position(match.end())
                if Tag(self.type, match.start(), match.end()) not in self.frame.current_annotations:
                    self.frame.wish_to_add = [self.type, cur_start, cur_end]
                    self.frame.add_annotation(None, remove_focus=False)
        except tkinter.TclError:
            raise
        self.frame.type_combos[self.level].current(0)
        self.frame.wish_to_add = None
        self.frame.current_selection = None
        self.frame.current_type_hierarchy_level = 0
        self.frame.update_level()
        self.frame.text.tag_remove("BOLD",  "1.0", 'end') 
开发者ID:YoannDupont,项目名称:SEM,代码行数:25,代码来源:misc.py

示例2: test_sre_character_class_literals

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def test_sre_character_class_literals(self):
        for i in [0, 8, 16, 32, 64, 127, 128, 255, 256, 0xFFFF, 0x10000, 0x10FFFF]:
            if i < 256:
                self.assertIsNotNone(re.match(r"[\%o]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\%o8]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\%03o]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\%03o0]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\%03o8]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\x%02x]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\x%02x0]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\x%02xz]" % i, chr(i)))
            if i < 0x10000:
                self.assertIsNotNone(re.match(r"[\u%04x]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\u%04x0]" % i, chr(i)))
                self.assertIsNotNone(re.match(r"[\u%04xz]" % i, chr(i)))
            self.assertIsNotNone(re.match(r"[\U%08x]" % i, chr(i)))
            self.assertIsNotNone(re.match(r"[\U%08x0]" % i, chr(i)+"0"))
            self.assertIsNotNone(re.match(r"[\U%08xz]" % i, chr(i)+"z"))
        self.assertIsNotNone(re.match(r"[\U0001d49c-\U0001d4b5]", "\U0001d49e"))
        self.assertRaises(re.error, re.match, r"[\911]", "")
        self.assertRaises(re.error, re.match, r"[\x1z]", "")
        self.assertRaises(re.error, re.match, r"[\u123z]", "")
        self.assertRaises(re.error, re.match, r"[\U0001234z]", "")
        self.assertRaises(re.error, re.match, r"[\U00110000]", "") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:26,代码来源:test_re.py

示例3: test_sre_byte_literals

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def test_sre_byte_literals(self):
        for i in [0, 8, 16, 32, 64, 127, 128, 255]:
            self.assertIsNotNone(re.match((r"\%03o" % i).encode(), bytes([i])))
            self.assertIsNotNone(re.match((r"\%03o0" % i).encode(), bytes([i])+b"0"))
            self.assertIsNotNone(re.match((r"\%03o8" % i).encode(), bytes([i])+b"8"))
            self.assertIsNotNone(re.match((r"\x%02x" % i).encode(), bytes([i])))
            self.assertIsNotNone(re.match((r"\x%02x0" % i).encode(), bytes([i])+b"0"))
            self.assertIsNotNone(re.match((r"\x%02xz" % i).encode(), bytes([i])+b"z"))
        self.assertIsNotNone(re.match(br"\u", b'u'))
        self.assertIsNotNone(re.match(br"\U", b'U'))
        self.assertIsNotNone(re.match(br"\0", b"\000"))
        self.assertIsNotNone(re.match(br"\08", b"\0008"))
        self.assertIsNotNone(re.match(br"\01", b"\001"))
        self.assertIsNotNone(re.match(br"\018", b"\0018"))
        self.assertIsNotNone(re.match(br"\567", bytes([0o167])))
        self.assertRaises(re.error, re.match, br"\911", b"")
        self.assertRaises(re.error, re.match, br"\x1", b"")
        self.assertRaises(re.error, re.match, br"\x1z", b"") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:test_re.py

示例4: getmatch

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def getmatch(self, haystack):
        if not isinstance(haystack, basestring):
            return None
        flags = 0
        if self.flags is not None:
            if "i" in self.flags or "I" in self.flags:
                flags |= re.I
            if "l" in self.flags or "L" in self.flags:
                flags |= re.L
            if "m" in self.flags or "M" in self.flags:
                flags |= re.M
            if "s" in self.flags or "S" in self.flags:
                flags |= re.S
            if "u" in self.flags or "U" in self.flags:
                flags |= re.U
            if "x" in self.flags or "X" in self.flags:
                flags |= re.X
        if re.match(self.pattern, haystack, flags=flags) is None:
            return None
        elif self.to is None:
            return Match(haystack, haystack)
        else:
            return Match(haystack, re.sub(self.pattern, self.to, haystack, flags=flags)) 
开发者ID:modelop,项目名称:hadrian,代码行数:25,代码来源:tools.py

示例5: setup

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def setup(self, config):
    """
    Compile configured regular expressions.

    :param config: Configuration object.
    :type config: ``dict``
    """
    self.matches = {}

    patterns = []

    for entity_type, pattern_conf in config.get(helper.ENTITIES, {}).items():
      patterns.append(
          r'\b(?P<{}>{})\b'.format(entity_type, pattern_conf[helper.PATTERN]))

    self.pattern = regex.compile(
        '|'.join(patterns),
        regex.I | regex.U) 
开发者ID:pcbje,项目名称:gransk,代码行数:20,代码来源:find_entities.py

示例6: get_dell_model

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def get_dell_model(sn, model):
    """
    返回Dell设备SN号对应的设备型号
    """
    query_url = "http://www.dell.com/support/home/cn/zh/cnbsdt1/product-support/servicetag/"
    pattern = "deel|dell|PowerEdge|R7|R8|R6|R4|戴尔"
    if re.findall(pattern, model, re.M | re.I | re.U):
        try:
            url = "{0}{1}".format(query_url, sn)
            response = urllib.request(url, timeout=30)
            html = response.read()
            _model = ''.join(re.findall(r'productName:"(.*?)"', html))
            _code = ''.join(re.findall(
                r'<span class="beforeCaptcha">(.*?)</span>', html))
        except:
            _model = model
            _code = None
    else:
        _model = model
        _code = None
    return _model, _code 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:23,代码来源:tasks.py

示例7: __init__

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def __init__(self):
        super(Tokeniser, self).__init__()
        
        self._cls         = re.compile(r"(-je|-tu|-nous|-vous|(:?-t)?-(:?on|ils?|elles?))\b", re.U + re.I)
        self._is_abn      = re.compile(r"\b(dr|me?lles?|mme?s?|mr?s?|st)\b\.?", re.U + re.I)
        self._abbrev      = re.compile(r"\b(i\.e\.|e\.g\.|c-à-d)", re.U + re.I)
        self._digit_valid = set(u"0123456789,.-")
        
        self._forbidden.append(self._is_abn)
        self._forbidden.append(self._abbrev)
        
        self._force.append(self._cls)
        
        self._spaces = re.compile(u"\s+", re.U+re.M)
        self._word = re.compile(u"^[^\W\d]+$", re.U + re.M)
        self._number_with_unit = re.compile(u"([0-9][^0-9,.])|([^0-9,.][0-9])")
        self._atomic = re.compile(u"[;:«»()\\[\\]{}=+*$£€/\\\"?!…%€$£]")
        self._comma_not_number = re.compile(u"(?<=[^0-9]),(?![0-9])", re.U + re.M)
        self._apostrophe = re.compile(u"(?=['ʼ’])", re.U + re.M)
        self._clitics = re.compile(r"(-je|-tu|-nous|-vous|(:?-t)?-(:?on|ils?|elles?))$", re.U + re.I) 
开发者ID:YoannDupont,项目名称:SEM,代码行数:22,代码来源:fr.py

示例8: normalize

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def normalize(token):
    apostrophes = re.compile(u"[\u2019]", re.U)
    lower_a = re.compile(u"[àáâãäåæ]", re.U)
    upper_a = re.compile(u"[ÀÁÂÃÄÅÆ]", re.U)
    lower_e = re.compile(u"[éèêë]", re.U)
    upper_e = re.compile(u"[ÉÈÊË]", re.U)
    lower_i = re.compile(u"[ìíîï]", re.U)
    upper_i = re.compile(u"[ÌÍÎÏ]", re.U)
    
    normalized = apostrophes.sub(u"'", token)
    normalized = lower_a.sub(u"a", normalized)
    normalized = upper_a.sub(u"A", normalized)
    normalized = lower_e.sub(u"e", normalized)
    normalized = upper_e.sub(u"E", normalized)
    normalized = lower_i.sub(u"i", normalized)
    normalized = upper_i.sub(u"I", normalized)
    return normalized 
开发者ID:YoannDupont,项目名称:SEM,代码行数:19,代码来源:label_consistency.py

示例9: test_ignore_case

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def test_ignore_case(self):
        self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match("abc", u"ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match(r"(a\s[^a])", "a b", re.I).group(1), "a b")
        self.assertEqual(re.match(r"(a\s[^a]*)", "a bb", re.I).group(1), "a bb")
        self.assertEqual(re.match(r"(a\s[abc])", "a b", re.I).group(1), "a b")
        self.assertEqual(re.match(r"(a\s[abc]*)", "a bb", re.I).group(1), "a bb")
        self.assertEqual(re.match(r"((a)\s\2)", "a a", re.I).group(1), "a a")
        self.assertEqual(re.match(r"((a)\s\2*)", "a aa", re.I).group(1), "a aa")
        self.assertEqual(re.match(r"((a)\s(abc|a))", "a a", re.I).group(1), "a a")
        self.assertEqual(re.match(r"((a)\s(abc|a)*)", "a aa", re.I).group(1), "a aa")

        if have_unicode:
            assert u(r'\u212a').lower() == u'k' # 'K'
            self.assertTrue(re.match(ur'K', u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(ur'k', u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'\u212a'), u'K', re.U | re.I))
            self.assertTrue(re.match(u(r'\u212a'), u'k', re.U | re.I))
            assert u(r'\u017f').upper() == u'S' # 'ſ'
            self.assertTrue(re.match(ur'S', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(ur's', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(u(r'\u017f'), u'S', re.U | re.I))
            self.assertTrue(re.match(u(r'\u017f'), u's', re.U | re.I)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_re.py

示例10: test_ignore_case_set

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def test_ignore_case_set(self):
        self.assertTrue(re.match(r'[19A]', 'A', re.I))
        self.assertTrue(re.match(r'[19a]', 'a', re.I))
        self.assertTrue(re.match(r'[19a]', 'A', re.I))
        self.assertTrue(re.match(r'[19A]', 'a', re.I))
        if have_unicode:
            self.assertTrue(re.match(ur'[19A]', u'A', re.U | re.I))
            self.assertTrue(re.match(ur'[19a]', u'a', re.U | re.I))
            self.assertTrue(re.match(ur'[19a]', u'A', re.U | re.I))
            self.assertTrue(re.match(ur'[19A]', u'a', re.U | re.I))
            assert u(r'\u212a').lower() == u'k' # 'K'
            self.assertTrue(re.match(u(r'[19K]'), u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19k]'), u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u212a]'), u'K', re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u212a]'), u'k', re.U | re.I))
            assert u(r'\u017f').upper() == u'S' # 'ſ'
            self.assertTrue(re.match(ur'[19S]', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(ur'[19s]', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u017f]'), u'S', re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u017f]'), u's', re.U | re.I)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_re.py

示例11: test_cp16657

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def test_cp16657(self):
        self.assertTrue(re.compile(r'^bar', re.M).search('foo\nbar') != None)
        self.assertTrue(re.compile(r'^bar(?m)').search('foo\nbar') != None)
        self.assertTrue(re.compile(r'^bar', re.M).search('foo\nbaar') == None)
        self.assertTrue(re.compile(r'^bar(?m)').search('foo\nbaar') == None)

        self.assertTrue(re.compile(r'^bar', re.U).search('bar') != None)
        self.assertTrue(re.compile(r'^bar(?u)').search('bar') != None)
        self.assertTrue(re.compile(r'^bar', re.U).search('baar') == None)
        self.assertTrue(re.compile(r'^bar(?u)').search('baar') == None)

        self.assertTrue(re.compile(r'     b ar   ', re.X).search('bar') != None)
        self.assertTrue(re.compile(r'b ar(?x)').search('bar') != None)
        self.assertTrue(re.compile(r'     b ar   ', re.X).search('baar') == None)
        self.assertTrue(re.compile(r'b ar(?x)').search('baar') == None)
        self.assertTrue(re.compile(r'b ar').search('bar') == None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_re.py

示例12: add_refs

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def add_refs(self, data):
        """Modify data according to the expected output."""
        if self.getRefs:
            titl_re = ur'(%s)' % '|'.join([re.escape(x) for x
                                            in self._titlesRefs.keys()])
            if titl_re != ur'()': re_titles = re.compile(titl_re, re.U)
            else: re_titles = None
            nam_re = ur'(%s)' % '|'.join([re.escape(x) for x
                                            in self._namesRefs.keys()])
            if nam_re != ur'()': re_names = re.compile(nam_re, re.U)
            else: re_names = None
            chr_re = ur'(%s)' % '|'.join([re.escape(x) for x
                                            in self._charactersRefs.keys()])
            if chr_re != ur'()': re_characters = re.compile(chr_re, re.U)
            else: re_characters = None
            _putRefs(data, re_titles, re_names, re_characters)
        return {'data': data, 'titlesRefs': self._titlesRefs,
                'namesRefs': self._namesRefs,
                'charactersRefs': self._charactersRefs} 
开发者ID:skarlekar,项目名称:faces,代码行数:21,代码来源:utils.py

示例13: __init__

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def __init__(self, state, regex, actions, next_state):
    """Initializes an event filter expressions parser token.

    Args:
      state (str): parser state within the token should be applied or None if
          the token should be applied regardless of the parser state.
      regex (str): regular expression to try and match from the current point.
      actions (list[str]): list of method names in the
          EventFilterExpressionParser to call.
      next_state (str): next state we transition to if this Token matches.
    """
    super(Token, self).__init__()
    self._regex = re.compile(regex, re.DOTALL | re.I | re.M | re.S | re.U)
    self.actions = []
    self.next_state = next_state
    self.state = state

    if actions:
      self.actions = actions.split(self._ACTION_SEPARATOR) 
开发者ID:log2timeline,项目名称:plaso,代码行数:21,代码来源:expression_parser.py

示例14: remove_types

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def remove_types(text, clean=clean_strict):
    """Remove company type names from a piece of text.

    WARNING: This converts to ASCII by default, pass in a different
    `clean` function if you need a different behaviour."""
    if not hasattr(remove_types, '_remove'):
        remove_types._remove = {}
    if clean not in remove_types._remove:
        names = set()
        with open(DATA_PATH, 'r') as fh:
            types = json.load(fh).get('types', {})
            # Compile person prefixes into a regular expression.
            for items in types.items():
                for item in items:
                    item = clean(item)
                    if item is not None:
                        names.add(item)
        forms = '(%s)' % '|'.join(names)
        remove_types._remove[clean] = re.compile(forms, re.U)
    text = clean(text)
    if text is not None:
        return remove_types._remove[clean].sub('', text).strip() 
开发者ID:alephdata,项目名称:fingerprints,代码行数:24,代码来源:replacers.py

示例15: sanitize_name

# 需要导入模块: import re [as 别名]
# 或者: from re import U [as 别名]
def sanitize_name(value: str) -> str:
    """
    Sanitizes a value to be safe to store in a Linux filesystem, in
    S3, and in a URL.  So unicode is allowed, but not special
    characters other than ".", "-", and "_".

    This implementation is based on django.utils.text.slugify; it is
    modified by:
    * adding '.' and '_' to the list of allowed characters.
    * preserving the case of the value.
    """
    value = unicodedata.normalize('NFKC', value)
    value = re.sub(r'[^\w\s._-]', '', value, flags=re.U).strip()
    value = re.sub(r'[-\s]+', '-', value, flags=re.U)
    assert value not in {'', '.', '..'}
    return mark_safe(value) 
开发者ID:zulip,项目名称:zulip,代码行数:18,代码来源:upload.py


注:本文中的re.U属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。