Python re.A Examples
The following are 30
code examples of re.A().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
re
, or try the search function
.
Example #1
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_string_boundaries(self): # See http://bugs.python.org/issue10713 self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1), "abc") # There's a word boundary at the start of a string. self.assertTrue(re.match(r"\b", "abc")) # A non-empty string includes a non-boundary zero-length match. self.assertTrue(re.search(r"\B", "abc")) # There is no non-boundary match at the start of a string. self.assertFalse(re.match(r"\B", "abc")) # However, an empty string contains no word boundaries, and also no # non-boundaries. self.assertIsNone(re.search(r"\B", "")) # This one is questionable and different from the perlre behaviour, # but describes current behavior. self.assertIsNone(re.search(r"\b", "")) # A single word-character string has two boundaries, but no # non-boundary gaps. self.assertEqual(len(re.findall(r"\b", "a")), 2) self.assertEqual(len(re.findall(r"\B", "a")), 0) # If there are no words, there are no boundaries self.assertEqual(len(re.findall(r"\b", " ")), 0) self.assertEqual(len(re.findall(r"\b", " ")), 0) # Can match around the whitespace. self.assertEqual(len(re.findall(r"\B", " ")), 2)
Example #2
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)) self.assertTrue(re.match(br'[19A]', b'A', re.I)) self.assertTrue(re.match(br'[19a]', b'a', re.I)) self.assertTrue(re.match(br'[19a]', b'A', re.I)) self.assertTrue(re.match(br'[19A]', b'a', re.I)) assert '\u212a'.lower() == 'k' # 'K' self.assertTrue(re.match(r'[19K]', '\u212a', re.I)) self.assertTrue(re.match(r'[19k]', '\u212a', re.I)) self.assertTrue(re.match(r'[19\u212a]', 'K', re.I)) self.assertTrue(re.match(r'[19\u212a]', 'k', re.I)) assert '\u017f'.upper() == 'S' # 'ſ' self.assertTrue(re.match(r'[19S]', '\u017f', re.I)) self.assertTrue(re.match(r'[19s]', '\u017f', re.I)) self.assertTrue(re.match(r'[19\u017f]', 'S', re.I)) self.assertTrue(re.match(r'[19\u017f]', 's', re.I)) assert '\ufb05'.upper() == '\ufb06'.upper() == 'ST' # 'ſt', 'st' self.assertTrue(re.match(r'[19\ufb05]', '\ufb06', re.I)) self.assertTrue(re.match(r'[19\ufb06]', '\ufb05', re.I))
Example #3
Source File: test_re.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_string_boundaries(self): # See http://bugs.python.org/issue10713 self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1), "abc") # There's a word boundary at the start of a string. self.assertTrue(re.match(r"\b", "abc")) # A non-empty string includes a non-boundary zero-length match. self.assertTrue(re.search(r"\B", "abc")) # There is no non-boundary match at the start of a string. self.assertFalse(re.match(r"\B", "abc")) # However, an empty string contains no word boundaries, and also no # non-boundaries. self.assertIsNone(re.search(r"\B", "")) # This one is questionable and different from the perlre behaviour, # but describes current behavior. self.assertIsNone(re.search(r"\b", "")) # A single word-character string has two boundaries, but no # non-boundary gaps. self.assertEqual(len(re.findall(r"\b", "a")), 2) self.assertEqual(len(re.findall(r"\B", "a")), 0) # If there are no words, there are no boundaries self.assertEqual(len(re.findall(r"\b", " ")), 0) self.assertEqual(len(re.findall(r"\b", " ")), 0) # Can match around the whitespace. self.assertEqual(len(re.findall(r"\B", " ")), 2)
Example #4
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)) self.assertTrue(re.match(br'[19A]', b'A', re.I)) self.assertTrue(re.match(br'[19a]', b'a', re.I)) self.assertTrue(re.match(br'[19a]', b'A', re.I)) self.assertTrue(re.match(br'[19A]', b'a', re.I)) assert '\u212a'.lower() == 'k' # 'K' self.assertTrue(re.match(r'[19K]', '\u212a', re.I)) self.assertTrue(re.match(r'[19k]', '\u212a', re.I)) self.assertTrue(re.match(r'[19\u212a]', 'K', re.I)) self.assertTrue(re.match(r'[19\u212a]', 'k', re.I)) assert '\u017f'.upper() == 'S' # 'ſ' self.assertTrue(re.match(r'[19S]', '\u017f', re.I)) self.assertTrue(re.match(r'[19s]', '\u017f', re.I)) self.assertTrue(re.match(r'[19\u017f]', 'S', re.I)) self.assertTrue(re.match(r'[19\u017f]', 's', re.I)) assert '\ufb05'.upper() == '\ufb06'.upper() == 'ST' # 'ſt', 'st' self.assertTrue(re.match(r'[19\ufb05]', '\ufb06', re.I)) self.assertTrue(re.match(r'[19\ufb06]', '\ufb05', re.I))
Example #5
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_string_boundaries(self): # See http://bugs.python.org/issue10713 self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1), "abc") # There's a word boundary at the start of a string. self.assertTrue(re.match(r"\b", "abc")) # A non-empty string includes a non-boundary zero-length match. self.assertTrue(re.search(r"\B", "abc")) # There is no non-boundary match at the start of a string. self.assertFalse(re.match(r"\B", "abc")) # However, an empty string contains no word boundaries, and also no # non-boundaries. self.assertIsNone(re.search(r"\B", "")) # This one is questionable and different from the perlre behaviour, # but describes current behavior. self.assertIsNone(re.search(r"\b", "")) # A single word-character string has two boundaries, but no # non-boundary gaps. self.assertEqual(len(re.findall(r"\b", "a")), 2) self.assertEqual(len(re.findall(r"\B", "a")), 0) # If there are no words, there are no boundaries self.assertEqual(len(re.findall(r"\b", " ")), 0) self.assertEqual(len(re.findall(r"\b", " ")), 0) # Can match around the whitespace. self.assertEqual(len(re.findall(r"\B", " ")), 2)
Example #6
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_bytes(self): self.check(b'bytes pattern', "re.compile(b'bytes pattern')") self.check_flags(b'bytes pattern', re.A, "re.compile(b'bytes pattern', re.ASCII)")
Example #7
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_inline_flags(self): # Bug #1700 upper_char = chr(0x1ea0) # Latin Capital Letter A with Dot Bellow lower_char = chr(0x1ea1) # Latin Small Letter A with Dot Bellow p = re.compile(upper_char, re.I | re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile(lower_char, re.I | re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?i)' + upper_char, re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?i)' + lower_char, re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?iu)' + upper_char) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?iu)' + lower_char) q = p.match(upper_char) self.assertTrue(q)
Example #8
Source File: relib_test.py From CrossHair with MIT License | 5 votes |
def test_handle_ascii_wildcard(self): self.assertIsNotNone(eval_regex('1.2', re.A, '1x2', 0)) self.assertIsNotNone(eval_regex('1.2', re.A, '1\x002', 0)) self.assertIsNone(eval_regex('1.2', re.A, '111', 0))
Example #9
Source File: relib_test.py From CrossHair with MIT License | 5 votes |
def test_handle_ascii_numeric(self): self.assertIsNotNone(eval_regex('a\d', re.A, 'a3', 0)) self.assertIsNotNone(eval_regex('a\d', re.A, 'a0', 0)) self.assertIsNone(eval_regex('a\d', re.A, 'a-', 0))
Example #10
Source File: relib_test.py From CrossHair with MIT License | 5 votes |
def test_greedy_backtracking(self) -> None: def f(s: str) -> int: ''' pre: len(s) == 3 post: _ == 3 ''' return re.match('.+.', s, re.A | re.DOTALL).end() self.assertEqual(*check_ok(f))
Example #11
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_bug_1661(self): # Verify that flags do not get silently ignored with compiled patterns pattern = re.compile('.') self.assertRaises(ValueError, re.match, pattern, 'A', re.I) self.assertRaises(ValueError, re.search, pattern, 'A', re.I) self.assertRaises(ValueError, re.findall, pattern, 'A', re.I) self.assertRaises(ValueError, re.compile, pattern, re.I)
Example #12
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_bug_3629(self): # A regex that triggered a bug in the sre-code validator re.compile("(?P<quote>)(?(quote))")
Example #13
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_re_match(self): for string in 'a', S('a'): self.assertEqual(re.match('a', string).groups(), ()) self.assertEqual(re.match('(a)', string).groups(), ('a',)) self.assertEqual(re.match('(a)', string).group(0), 'a') self.assertEqual(re.match('(a)', string).group(1), 'a') self.assertEqual(re.match('(a)', string).group(1, 1), ('a', 'a')) for string in b'a', B(b'a'), bytearray(b'a'), memoryview(b'a'): self.assertEqual(re.match(b'a', string).groups(), ()) self.assertEqual(re.match(b'(a)', string).groups(), (b'a',)) self.assertEqual(re.match(b'(a)', string).group(0), b'a') self.assertEqual(re.match(b'(a)', string).group(1), b'a') self.assertEqual(re.match(b'(a)', string).group(1, 1), (b'a', b'a')) for a in ("\xe0", "\u0430", "\U0001d49c"): self.assertEqual(re.match(a, a).groups(), ()) self.assertEqual(re.match('(%s)' % a, a).groups(), (a,)) self.assertEqual(re.match('(%s)' % a, a).group(0), a) self.assertEqual(re.match('(%s)' % a, a).group(1), a) self.assertEqual(re.match('(%s)' % a, a).group(1, 1), (a, a)) pat = re.compile('((a)|(b))(c)?') self.assertEqual(pat.match('a').groups(), ('a', 'a', None, None)) self.assertEqual(pat.match('b').groups(), ('b', None, 'b', None)) self.assertEqual(pat.match('ac').groups(), ('a', 'a', None, 'c')) self.assertEqual(pat.match('bc').groups(), ('b', None, 'b', 'c')) self.assertEqual(pat.match('bc').groups(""), ('b', "", 'b', 'c')) # A single group m = re.match('(a)', 'a') self.assertEqual(m.group(0), 'a') self.assertEqual(m.group(0), 'a') self.assertEqual(m.group(1), 'a') self.assertEqual(m.group(1, 1), ('a', 'a')) pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?') self.assertEqual(pat.match('a').group(1, 2, 3), ('a', None, None)) self.assertEqual(pat.match('b').group('a1', 'b2', 'c3'), (None, 'b', None)) self.assertEqual(pat.match('ac').group(1, 'b2', 3), ('a', None, 'c'))
Example #14
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_getlower(self): import _sre self.assertEqual(_sre.getlower(ord('A'), 0), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.LOCALE), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.UNICODE), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.ASCII), ord('a')) self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC") self.assertEqual(re.match(b"abc", b"ABC", re.I).group(0), b"ABC") self.assertEqual(re.match("abc", "ABC", re.I|re.A).group(0), "ABC") self.assertEqual(re.match(b"abc", b"ABC", re.I|re.L).group(0), b"ABC")
Example #15
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_flags(self): for flag in [re.I, re.M, re.X, re.S, re.A, re.U]: self.assertTrue(re.compile('^pattern$', flag)) for flag in [re.I, re.M, re.X, re.S, re.A, re.L]: self.assertTrue(re.compile(b'^pattern$', flag))
Example #16
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_inline_flags(self): # Bug #1700 upper_char = '\u1ea0' # Latin Capital Letter A with Dot Below lower_char = '\u1ea1' # Latin Small Letter A with Dot Below p = re.compile(upper_char, re.I | re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile(lower_char, re.I | re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?i)' + upper_char, re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?i)' + lower_char, re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?iu)' + upper_char) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?iu)' + lower_char) q = p.match(upper_char) self.assertTrue(q) self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char)) self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))
Example #17
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_bug_13899(self): # Issue #13899: re pattern r"[\A]" should work like "A" but matches # nothing. Ditto B and Z. with self.assertWarns(DeprecationWarning): self.assertEqual(re.findall(r'[\A\B\b\C\Z]', 'AB\bCZ'), ['A', 'B', '\b', 'C', 'Z'])
Example #18
Source File: basictests.py From Transcrypt with Apache License 2.0 | 5 votes |
def checkFlagsExist(test): test.check(aValue(re.T)) test.check(aValue(re.I)) test.check(aValue(re.IGNORECASE)) test.check(aValue(re.M)) test.check(aValue(re.MULTILINE)) test.check(aValue(re.S)) test.check(aValue(re.DOTALL)) test.check(aValue(re.U)) test.check(aValue(re.UNICODE)) test.check(aValue(re.X)) test.check(aValue(re.VERBOSE)) test.check(aValue(re.A)) test.check(aValue(re.ASCII))
Example #19
Source File: number_parser.py From AV_Data_Capture with GNU General Public License v3.0 | 5 votes |
def get_number(filepath: str) -> str: """ >>> from number_parser import get_number >>> get_number("/Users/Guest/AV_Data_Capture/snis-829.mp4") 'snis-829' >>> get_number("/Users/Guest/AV_Data_Capture/snis-829-C.mp4") 'snis-829' >>> get_number("C:¥Users¥Guest¥snis-829.mp4") 'snis-829' >>> get_number("C:¥Users¥Guest¥snis-829-C.mp4") 'snis-829' >>> get_number("./snis-829.mp4") 'snis-829' >>> get_number("./snis-829-C.mp4") 'snis-829' >>> get_number(".¥snis-829.mp4") 'snis-829' >>> get_number(".¥snis-829-C.mp4") 'snis-829' >>> get_number("snis-829.mp4") 'snis-829' >>> get_number("snis-829-C.mp4") 'snis-829' """ filepath = os.path.basename(filepath) if '-' in filepath or '_' in filepath: # 普通提取番号 主要处理包含减号-和_的番号 filepath = filepath.replace("_", "-") filepath.strip('22-sht.me').strip('-HD').strip('-hd') filename = str(re.sub("\[\d{4}-\d{1,2}-\d{1,2}\] - ", "", filepath)) # 去除文件名中时间 if 'FC2' or 'fc2' in filename: filename = filename.replace('PPV','').replace('ppv','').replace('--','-').replace('_','-') file_number = re.search(r'\w+-\w+', filename, re.A).group() return file_number else: # 提取不含减号-的番号,FANZA CID try: return str(re.findall(r'(.+?)\.', str(re.search('([^<>/\\\\|:""\\*\\?]+)\\.\\w+$', filepath).group()))).strip("['']").replace('_', '-') except: return re.search(r'(.+?)\.', filepath)[0]
Example #20
Source File: channel.py From asynqp with MIT License | 5 votes |
def set_return_handler(self, handler): """ Set ``handler`` as the callback function for undeliverable messages that were returned by the server. By default, an exception is raised, which will be handled by the event loop's exception handler (see :meth:`BaseEventLoop.set_exception_handler <asyncio.BaseEventLoop.set_exception_handler>`). If ``handler`` is None, this default behaviour is set. :param callable handler: A function to be called when a message is returned. The callback will be passed the undelivered message. """ self.basic_return_consumer.set_callback(handler)
Example #21
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_bug_1661(self): # Verify that flags do not get silently ignored with compiled patterns pattern = re.compile('.') self.assertRaises(ValueError, re.match, pattern, 'A', re.I) self.assertRaises(ValueError, re.search, pattern, 'A', re.I) self.assertRaises(ValueError, re.findall, pattern, 'A', re.I) self.assertRaises(ValueError, re.compile, pattern, re.I)
Example #22
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_bug_3629(self): # A regex that triggered a bug in the sre-code validator re.compile("(?P<quote>)(?(quote))")
Example #23
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_re_match(self): for string in 'a', S('a'): self.assertEqual(re.match('a', string).groups(), ()) self.assertEqual(re.match('(a)', string).groups(), ('a',)) self.assertEqual(re.match('(a)', string).group(0), 'a') self.assertEqual(re.match('(a)', string).group(1), 'a') self.assertEqual(re.match('(a)', string).group(1, 1), ('a', 'a')) for string in b'a', B(b'a'), bytearray(b'a'), memoryview(b'a'): self.assertEqual(re.match(b'a', string).groups(), ()) self.assertEqual(re.match(b'(a)', string).groups(), (b'a',)) self.assertEqual(re.match(b'(a)', string).group(0), b'a') self.assertEqual(re.match(b'(a)', string).group(1), b'a') self.assertEqual(re.match(b'(a)', string).group(1, 1), (b'a', b'a')) for a in ("\xe0", "\u0430", "\U0001d49c"): self.assertEqual(re.match(a, a).groups(), ()) self.assertEqual(re.match('(%s)' % a, a).groups(), (a,)) self.assertEqual(re.match('(%s)' % a, a).group(0), a) self.assertEqual(re.match('(%s)' % a, a).group(1), a) self.assertEqual(re.match('(%s)' % a, a).group(1, 1), (a, a)) pat = re.compile('((a)|(b))(c)?') self.assertEqual(pat.match('a').groups(), ('a', 'a', None, None)) self.assertEqual(pat.match('b').groups(), ('b', None, 'b', None)) self.assertEqual(pat.match('ac').groups(), ('a', 'a', None, 'c')) self.assertEqual(pat.match('bc').groups(), ('b', None, 'b', 'c')) self.assertEqual(pat.match('bc').groups(""), ('b', "", 'b', 'c')) # A single group m = re.match('(a)', 'a') self.assertEqual(m.group(0), 'a') self.assertEqual(m.group(0), 'a') self.assertEqual(m.group(1), 'a') self.assertEqual(m.group(1, 1), ('a', 'a')) pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?') self.assertEqual(pat.match('a').group(1, 2, 3), ('a', None, None)) self.assertEqual(pat.match('b').group('a1', 'b2', 'c3'), (None, 'b', None)) self.assertEqual(pat.match('ac').group(1, 'b2', 3), ('a', None, 'c'))
Example #24
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_getlower(self): import _sre self.assertEqual(_sre.getlower(ord('A'), 0), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.LOCALE), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.UNICODE), ord('a')) self.assertEqual(_sre.getlower(ord('A'), re.ASCII), ord('a')) self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC") self.assertEqual(re.match(b"abc", b"ABC", re.I).group(0), b"ABC") self.assertEqual(re.match("abc", "ABC", re.I|re.A).group(0), "ABC") self.assertEqual(re.match(b"abc", b"ABC", re.I|re.L).group(0), b"ABC")
Example #25
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_flags(self): for flag in [re.I, re.M, re.X, re.S, re.A, re.U]: self.assertTrue(re.compile('^pattern$', flag)) for flag in [re.I, re.M, re.X, re.S, re.A, re.L]: self.assertTrue(re.compile(b'^pattern$', flag))
Example #26
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_inline_flags(self): # Bug #1700 upper_char = '\u1ea0' # Latin Capital Letter A with Dot Below lower_char = '\u1ea1' # Latin Small Letter A with Dot Below p = re.compile(upper_char, re.I | re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile(lower_char, re.I | re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?i)' + upper_char, re.U) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?i)' + lower_char, re.U) q = p.match(upper_char) self.assertTrue(q) p = re.compile('(?iu)' + upper_char) q = p.match(lower_char) self.assertTrue(q) p = re.compile('(?iu)' + lower_char) q = p.match(upper_char) self.assertTrue(q)
Example #27
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_bug_13899(self): # Issue #13899: re pattern r"[\A]" should work like "A" but matches # nothing. Ditto B and Z. with self.assertWarns(DeprecationWarning): self.assertEqual(re.findall(r'[\A\B\b\C\Z]', 'AB\bCZ'), ['A', 'B', '\b', 'C', 'Z'])
Example #28
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_basic_re_sub(self): self.assertTypedEqual(re.sub('y', 'a', 'xyz'), 'xaz') self.assertTypedEqual(re.sub('y', S('a'), S('xyz')), 'xaz') self.assertTypedEqual(re.sub(b'y', b'a', b'xyz'), b'xaz') self.assertTypedEqual(re.sub(b'y', B(b'a'), B(b'xyz')), b'xaz') self.assertTypedEqual(re.sub(b'y', bytearray(b'a'), bytearray(b'xyz')), b'xaz') self.assertTypedEqual(re.sub(b'y', memoryview(b'a'), memoryview(b'xyz')), b'xaz') for y in ("\xe0", "\u0430", "\U0001d49c"): self.assertEqual(re.sub(y, 'a', 'x%sz' % y), 'xaz') self.assertEqual(re.sub("(?i)b+", "x", "bbbb BBBB"), 'x x') self.assertEqual(re.sub(r'\d+', self.bump_num, '08.2 -2 23x99y'), '9.3 -3 24x100y') self.assertEqual(re.sub(r'\d+', self.bump_num, '08.2 -2 23x99y', 3), '9.3 -3 23x99y') self.assertEqual(re.sub('.', lambda m: r"\n", 'x'), '\\n') self.assertEqual(re.sub('.', r"\n", 'x'), '\n') s = r"\1\1" self.assertEqual(re.sub('(.)', s, 'x'), 'xx') self.assertEqual(re.sub('(.)', re.escape(s), 'x'), s) self.assertEqual(re.sub('(.)', lambda m: s, 'x'), s) self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx'), 'xxxx') self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx'), 'xxxx') self.assertEqual(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx'), 'xxxx') self.assertEqual(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx'), 'xxxx') self.assertEqual(re.sub('a',r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D','a'), '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D') self.assertEqual(re.sub('a', '\t\n\v\r\f\a', 'a'), '\t\n\v\r\f\a') self.assertEqual(re.sub('a', '\t\n\v\r\f\a', 'a'), (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7))) self.assertEqual(re.sub('^\s*', 'X', 'test'), 'Xtest')
Example #29
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_bug_1661(self): # Verify that flags do not get silently ignored with compiled patterns pattern = re.compile('.') self.assertRaises(ValueError, re.match, pattern, 'A', re.I) self.assertRaises(ValueError, re.search, pattern, 'A', re.I) self.assertRaises(ValueError, re.findall, pattern, 'A', re.I) self.assertRaises(ValueError, re.compile, pattern, re.I)
Example #30
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_bug_3629(self): # A regex that triggered a bug in the sre-code validator re.compile("(?P<quote>)(?(quote))")