Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้ Wildcard ใน Python Regular Expression

ใช้ regex . (dot) เป็น wildcard จับคู่ตัวอักษรใดก็ตามยกเว้น newline

ตัวอย่าง

import re
rex = re.compile('th.s')
l = "this, thus, just, then"
print(rex.findall(l))

ผลลัพธ์

['this', 'thus']