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

Python Regex สำหรับเช็ค Alphanumeric String

ใช้ re.match() กับ pattern ^[a-zA-Z0-9]+$

ตัวอย่าง

>> import re
>>> bool(re.match('^[a-zA-Z0-9]+$', '789def'))
True
>>> bool(re.match('^[a-zA-Z0-9]+$', '789#%$def'))
False