比较变量中的多行字符串

时间:2011-09-16 10:12:58

标签: python string

如何使用python检查文件中是否存在para。

例如,sampleData是     backtick escapes like _so_ quote by placing > at start of line to make links <http://foo.com> [foo](http://foo.com) <a href="http://foo.com">foo</a>

我想搜索
quote by placing > at start of line to make links <http://foo.com>

我尝试了普通的搜索功能,例如sampledata.find('引用&gt;引用行开头)     建立链接     http://foo.com')实际上没有用。

2 个答案:

答案 0 :(得分:0)

in运算符和任何搜索函数都可以正常工作:

>>> needle = '`Searching > for text`'
>>> haystack = 'You are `Searching > for text`, are you not?'
>>> needle in haystack
True

如果您想要更高级的匹配(例如跳过某些字符,并在其间允许任意空格),请使用regular expression

答案 1 :(得分:0)

根据您的样本数据:

>>> '<strong><u></u></strong></p> <span class="info">'.find('</p> <span class="info">')
24
相关问题