def test_re_findall(self): self.assertEqual(re.findall(":+", "abc"), []) self.assertEqual(re.findall(":+", "a:b::c:::d"), [":", "::", ":::"]) self.assertEqual(re.findall("(:+)", "a:b::c:::d"), [":", "::", ":::"]) self.assertEqual(re.findall("(:)(:*)", "a:b::c:::d"), [(":", ""), (":", ":"), (":", "::")])
def main(): seq = stdin.read() write = stdout.write ilen = len(seq) seq = sub('>.*\n|\n', '', seq) clen = len(seq) variants = ( 'agggtaaa|tttaccct', '[cgt]gggtaaa|tttaccc[acg]', 'a[act]ggtaaa|tttacc[agt]t', 'ag[act]gtaaa|tttac[agt]ct', 'agg[act]taaa|ttta[agt]cct', 'aggg[acg]aaa|ttt[cgt]ccct', 'agggt[cgt]aa|tt[acg]accct', 'agggta[cgt]a|t[acg]taccct', 'agggtaa[cgt]|[acg]ttaccct') for f in variants: write(f + ' ' +str(len(findall(f, seq))).encode('latin1') + '\n') subst = { 'B' : '(c|g|t)', 'D' : '(a|g|t)', 'H' : '(a|c|t)', 'K' : '(g|t)', 'M' : '(a|c)', 'N' : '(a|c|g|t)', 'R' : '(a|g)', 'S' : '(c|g)', 'V' : '(a|c|g)', 'W' : '(a|t)', 'Y' : '(c|t)'} for f, r in subst.items(): seq = sub(f, r, seq) write('\n') write(str(ilen).encode('latin1') + '\n') write(str(clen).encode('latin1') + '\n') write(str(len(seq)).encode('latin1') + '\n')
def test_re_escape_non_ascii_bytes(self): b = u'y\u2620y\u2620y'.encode('utf-8') b_escaped = re.escape(b) self.assertEqual(b_escaped, b'y\\\xe2\\\x98\\\xa0y\\\xe2\\\x98\\\xa0y') self.assertMatch(b_escaped, b) res = re.findall(re.escape(u'\u2620'.encode('utf-8')), b) self.assertEqual(len(res), 2)
def test_bug_117612(self): self.assertEqual(re.findall(r"(a|(b))", "aba"), [("a", ""),("b", "b"),("a", "")])