當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。