У меня есть регулярное выражение, которое должно соответствовать restrutureText
содержимому, но оно странно.
import re
# match regular expression such as
# ===, ---, ^^^ for heading,
# ... anyword:, :anyword: for directive
Regx = re.compile(r'^(====)?|^(-----)?|..\s+\w+::|(^)|(\.\.\s+\w+)?::$|^(\^\^\^\^)|:\w+:')
Text = """
# blogger
`blogger` is a command line utility originally created for converting articles, text, or HTML into speech. This is especially helpful for bloggers who like to provide audio options for their users.
This is a wrapper around a couple of different text to speech tools and is designed to be a simple interface for any user of the `blogger` CLI.
`blogger` is an open-source project from Buster Technologies, the creators of [Buster ERP](https://bustererp.com). Our company published technical and business content on the [Simpler Software Blog](https://bustererp.com/blog) and needed a simple tool to convert articles to audio files.
"""
TrueOrFalse = re.match(Regx, Text)
if TrueOrFalse:
print 'It is a restructureText.'
else:
print 'It is a plain text or markdown.'
Проверено на regex101.com , я не знаю, почему мой Регкс соответствует началу текста, как это. Спасибо.
Добавлено:
Приведенный выше фрагмент, поскольку введенный текст, который является переменной Text
, имеет синтаксис markdown
, он не должен совпадать ни с одним, пока в if-statement
, он возвращает True
и печатает «Это текст реструктуризации». в результате, что неверно.
Текст, который должен соответствовать моему регулярному выражению, представляет собой синтаксис restructureText, подобный этому
=======
Abathur
=======
.. image:: https://travis-ci.org/yeyuexia/dummie.svg?branch=master
:target: https://travis-ci.org/yeyuexia/dummie
Simple Template manager to manage template and create project based on template.
Requirements
------------
* Python 3.6+
* Works on Linux, Windows, Mac OSX, BSD
Install
-------
pip::
pip install abathur
Мой регулярное выражение соответствует этому введенному тексту, но также соответствует одному в первом фрагменте, чего не должно быть.
Что не так с моим обычным express? как я могу это исправить? Спасибо