รหัสต่อไปนี้ตรวจสอบตัวเลขว่าเท่ากับ '2018'
ตัวอย่าง
import re s = '2018' match = re.match(r'\b2018\b',s) print match.group()
ผลลัพธ์
สิ่งนี้ให้ผลลัพธ์
2018
ตัวอย่าง
รหัสต่อไปนี้ตรวจสอบจำนวนเต็มบวกห้าหลักใดๆ
import re
s = '2346'
match = re.match(r'(?<!-)\b[1-9]\d{4}\b',s)
print match
s2 = '56789'
match = re.match(r'(?<!-)\b[1-9]\d{4}\b',s2)
print match.group() ผลลัพธ์
None 56789