Форум сайта python.su
всем здравствуйте.
помогите написать регулярку.
нужно найти строчку: Inserts a command to the server queue at the beginning and forces execution.
import re
text ='''
<p><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script>
</p><p><br />
</p>
<div class="editsection" style="float:right;margin-left:5px;">[<a href="/w/Template:Method/edit?section=4" title="Template:Method">edit</a>]</div><a name="Description"></a><h3>Description</h3>
<p>Inserts a command to the server queue at the beginning and forces execution.
</p>
<div class="editsection" style="float:right;margin-left:5px;">[<a href="/w/Template:Method/edit?section=5" title="Template:Method">edit</a>]</div><a name="Arguments"></a><h3>Arguments</h3>
<p><br />
</p>
'''
print re.findall(r"Description</h3>(.*?)</p>", text)
Офлайн
re.search('Inserts a command to the server queue at the beginning and forces execution.', text)
Офлайн
А регулярка то тут зачем? Просто ищите строчку.
Офлайн
Мне кажется что sp3 нужно найти эту строку, не зная ее. Т е вычистить из файла теги.
Офлайн
print re.findall(r"Description</h3>\s*<p[^>]*>(.*?)</p>", text, re.S | re.I)
Офлайн
print re.findall(r"Description</h3>\n<p>(.*?)</p>", text, re.DOTALL)
print re.findall(r"Description</h3>\s+<p>(.*?)</p>", text, re.DOTALL)
Офлайн
Nikа зачем "<p*>“ , там же ”<p>" - 3 символа вместеprint re.findall(r"Description</h3>\s*<p[^>]*>(.*?)</p>", text, re.S | re.I)
Офлайн
а зачем "<p*>“ , там же ”<p>" - 3 символа вместеОткрывающие теги могут иметь (или не иметь) параметры… Вы же пытаетесь решить конкретную ситуацию, а не предвидеть возможные варианты…
Офлайн
Nik,o7412369815963 спасибо, очень помогли :)
Офлайн
Nikтак и есть, т.к. это статический шаблон, изменяется только текст.
Вы же пытаетесь решить конкретную ситуацию
Отредактировано (Июнь 10, 2010 15:54:44)
Офлайн