본문 바로가기
파이썬

파이썬 문자열을 대문자로 분할

by º기록 2020. 12. 18.
반응형


예를 들어 분할하고 싶습니다. 'TheLongAndWindingRoad' at any occurrence of an uppercase letter (possibly except the first), and obtain [ 'The', 'Long', 'And', 'Winding', 'Road'] .

편집 : 또한 단일 발생을 분할해야합니다. from 'ABC' I'd like to obtain [ 'A', 'B', 'C'] .

 

해결 방법

 


>>> import re
>>> re.findall('[A-Z][^A-Z]*', 'TheLongAndWindingRoad')
['The', 'Long', 'And', 'Winding', 'Road']
>>> re.findall('[A-Z][^A-Z]*', 'ABC')
['A', 'B', 'C']

 

참조 페이지 https://stackoverflow.com/questions/2277352

 

 

반응형

댓글