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

วิธี split ด้วย newline characters ติดต่อกันใน Python Regex

ใช้ regex split สตริงด้วย newline characters ที่ติดต่อกัน

ตัวอย่าง

import re
s = """I find     Tutorialspoint     useful"""
print(re.split(r"[\n]", s))

ผลลัพธ์

['I find', '     Tutorialspoint', '     useful']