Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 여러 구분 기호가 있는 문자열을 어떻게 깰 수 있습니까?

<시간/>

re.split(delimiter, str) 메서드를 사용하여 여러 구분 기호로 문자열을 깰 수 있습니다. 구분 기호의 정규식과 분할해야 하는 문자열이 필요합니다. 예:

a='Beautiful, is; better*than\nugly'
import re
print(re.split('; |, |\*|\n',a))

출력을 얻습니다.

['Beautiful', 'is', 'better', 'than', 'ugly']