擅长:python、mysql、java
<p>您可以使用正则表达式(使用<a href="https://docs.python.org/2/library/re.html" rel="nofollow noreferrer">^{<cd1>}</a>模块)检查如下日期:</p>
<pre><code>import re
with open('file.txt', 'r') as text_file:
data = []
for line in text_file:
row = line.strip()
if re.match(r'\d{2}/\d{2}/\d{4}.*'):
data.append(row) # date: new record
else:
data[-1] += '\n' + row # no date: append to last record
# '\d{2}': two digits
# '.*': any character, zero or more times
</code></pre>