Versus-ni qidirish
Python oddiy iboralar asosida ikkita turli xil ibtidoiy operatsiyalarni taklif qiladi
: matchni faqat satr boshida tekshirish, a ni qidirish
satrning istalgan joyiga moslashtiring (bu Perlning odatiy holati).
Misol
#! / usr / bin / python3
import re
line = "Mushuklar itlarga qaraganda aqlli";
matchObj = re.match (r'dogs ', qator, re.M | re.I)
agar matchObj:
chop etish ("match -> matchObj.group ():", matchObj.group ())
yana:
chop etish ("Hech narsa topilmadi !!")
searchObj = re.search (r'dogs ', qator, re.M | re.I)
agar qidiruvObj:
Python 3
350
chop etish ("qidirish -> searchObj.group ():", searchObj.group ())
yana:
bosib chiqarish ("Hech narsa topilmadi !!")
Yuqoridagi kod bajarilganda, u quyidagi natijani beradi -
Hech narsa topilmadi !!
qidiruv -> matchObj.group (): itlar
Do'stlaringiz bilan baham: |