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

วิธีเขียน Python Regex ตรวจสอบตัวอักษร alphanumeric

ใน Python มี special sequence \w สำหรับจับคู่ alphanumeric และ underscore (เมื่อไม่ระบุ LOCALE และ UNICODE flags)

ตัวอย่าง

import re
result = re.search(r'^\w+$', 'Tutorials123')
print(result.group())

ผลลัพธ์

Tutorials123