0

我正在尝试解析一组引号之间的随机字符串。数据始终采用以下形式:

klheafoiehaiofa" randomtextnamehere.ext "fiojeaiof;jidoa;jfioda

我知道 .ext 是什么,我想要的是randomtextnamehere.ext,并且它总是用“”分隔。

目前我只能处理某些情况,但我希望能够处理任何情况,如果我可以从第一个“开始抓住”,然后在第二个“停止”,那就太好了。因为每行可能有不止一组 "。

谢谢!

4

1 回答 1

3

您可以使用以下str.split方法:

Docstring:
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.

In [1]: s = 'klheafoiehaiofa"randomtextnamehere.ext"fiojeaiof;jidoa;jfioda'

In [2]: s.split('"', 2)[1]
Out[2]: 'randomtextnamehere.ext'
于 2013-04-25T04:17:37.150 回答