无法让Python识别Escape Tab字符

时间:2017-11-21 02:38:43

标签: string python-2.7 split escaping

我是Python的新手,并且在看似简单的目标方面遇到了麻烦。我已经尝试了几种用制表符分割字符串的方法无济于事。

var buildClient = new BuildHttpClient(new Uri(collectionURL), new 
VssCredentials(true));
var res = await buildClient.QueueBuildAsync(new Build
            {
                Definition = new DefinitionReference
                {
                    Id = targetBuild.Id
                },
                Project = targetBuild.Project,
                SourceVersion = ChangeSetNumber,
                Parameters = buildArg

            });
            return res.Id.ToString();

结果

testStr = 'word1    word2'
    values = testStr.split("\t")
    print(values)

['word1    word2']

结果

import re
testStr = 'word1    word2'
print(str(re.search(r'[^\t]', testStr).start()))

使用以下帖子的答案:

How to get the first word in the string

splitting a string based on tab in the file

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您的testStr不以\t开头,因此在正则表达式模式中,您不需要^

所以在你的情况下它将是:

import re
testStr = 'word1\tword2'
print(str(re.search(r'[\t]', testStr).start()))

结果将是

5