_re.py 633 B

1234567891011121314151617
  1. import re
  2. # test match, search, sub, split
  3. m = re.search('测试','123测试测试')
  4. assert m.span() == (3,5)
  5. assert m.group(0) == '测试'
  6. assert re.match('测试','123测试测试') is None
  7. assert re.sub('测试','xxx','123测试12321测试') == '123xxx12321xxx'
  8. # this is different from cpython, the last empty string is not included
  9. assert re.split('测试','测试123测试12321测试') == ['', '123', '12321']
  10. assert re.split(',','123,456,789,10') == ['123', '456', '789', '10']
  11. assert re.split(',',',123,456,789,10') == ['', '123', '456', '789', '10']
  12. assert re.split(',','123,456,789,10,') == ['123', '456', '789', '10']