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

วิธีใช้ Python Regex Split สตริงด้วยหลาย delimiters

ใช้ Python regex split สตริงที่กำหนดด้วยหลาย delimiters

ตัวอย่าง

import re
s = 'Beautiful; Soup\n is, good: Python* application'
result = re.split('; |, |\*|\n|:', s)
print(result)

ผลลัพธ์

['Beautiful', 'Soup', ' is', 'good', ' Python', ' application']