따옴표로 감싼 substring은 보호하면서 공백문자로 스트링을 분할하는 방법에 대해
조회수 1716회
발생하는 문제 및 실행환경
'this is "a test"'
이런 스트링을 분할하는데
['this', 'is', 'a', 'test'] #이거 말고
['this', 'is', 'a test'] #이것!
같이 따옴표 안은 보호됬으면 좋겠습니다.
직접 함수를 짜려고하니 감이 안잡히는데 가이드 해주시면 좋겠습니다
1 답변
-
shlex모듈의 shlex.split()을 쓰면 됩니다.
import shlex shlex.split('this is "a test"') #['this', 'is', 'a test']
댓글 입력