python:模拟 scanf
Python 目前没有一个类似c函数 scanf() 的替代品。正则表达式通常比 scanf() 格式字符串要更强大一些,但也带来更多复杂性。下面的表格提供了 scanf() 格式符和正则表达式大致相同的映射。
从文件名和数字提取字符串
/usr/sbin/sendmail - 0 errors, 4 warnings
你可以使用 scanf() 格式化
%s - %d errors, %d warnings
等价的正则表达式是:
(\S+) - (\d+) errors, (\d+) warnings