Python shlex.split(),忽略单引号
在Python中,我如何使用shlex.split()或类似的分割字符串,只保留双引号?例如,如果输入是 "hello, world" is what 'i say'
则输出将为 ["hello, world", "is", "what", "'我”,“说”]
。
How, in Python, can I use shlex.split()
or similar to split strings, preserving only double quotes? For example, if the input is "hello, world" is what 'i say'
then the output would be ["hello, world", "is", "what", "'i", "say'"]
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
shlex.quotes
控制哪些字符将被视为字符串引号。您需要修改shlex.wordchars
同样,将'
与i
和say
保留在一起。You can use
shlex.quotes
to control which characters will be considered string quotes. You'll need to modifyshlex.wordchars
as well, to keep the'
with thei
and thesay
.