import re
hand = open('mbox-short.txt')
for line in hand:
line = line.rstrip()
if re.search('^From:', line) :
print(line)
hand = open('mbox-short.txt')
for line in hand:
line = line.rstrip()
if line.startswith('From:') :
print(line)
Biz satrga maxsus belgilar qo'shish orqali mos keladigan narsani aniqlaymiz
Wild-Card belgilar
X-Sieve: CMU Sieve 2.3
X-DSPAM-Result: Innocent
X-DSPAM-Confidence: 0.8475
X-Content-Type-Message-Body: text/plain
^X.*:
Chiziqning boshini moslang
Har qanday belgini moslashtiring
Ko'p marotaba
Moslikni nozik sozlash Ma'lumotlaringiz qanchalik "toza" ekanligiga va ilovangizning maqsadiga qarab, moslikni biroz qisqartirishni xohlashingiz mumkin.
X-Sieve: CMU Sieve 2.3
X-DSPAM-Result: Innocent
X-Plane is behind schedule: two weeks
X-: Very short
^X.*:
Chiziqning boshini moslang
Har qanday belgini moslashtiring
Ko'p marotaba
Moslikni nozik sozlash Ma'lumotlaringiz qanchalik "toza" ekanligiga va ilovangizning maqsadiga qarab, moslikni biroz qisqartirishni xohlashingiz mumkin.
X-Sieve: CMU Sieve 2.3
X-DSPAM-Result: Innocent
X-: Very Short
X-Plane is behind schedule: two weeks
^X-\S+:
Chiziqning boshini moslang
Bo'sh joy bo'lmagan har qanday belgini moslang
Bir yoki bir necha marta
- re.search() satrning oddiy ifodaga mos kelishiga qarab True/False qiymatini qaytaradi
- Agar biz mos keladigan satrlarni chiqarib olishni istasak, biz re.findall() dan foydalanamiz.
>>> import re
>>> x = 'My 2 favorite numbers are 19 and 42'
>>> y = re.findall('[0-9]+',x)
>>> print(y)
['2', '19', '42']
[0-9]+
Bir yoki bir nechta raqam
Do'stlaringiz bilan baham: |