(word経由で)htmlに変換されたwordドキュメントの見出しタグからすべてのデータを抽出しようとしています
私は次の正規表現を持っています:
<(?<Class>h[5|6|7|8])>(?<ListIdentifier>.*?)<span style='font:7.0pt "Times New Roman"'>(?: )+.+</span>(?<Text>.*?)(?:</h[5|6|7|8]>)?
私の原文は次のようになります
<h5>(1)<span style='font:7.0pt "Times New Roman"'>
</span>The Scheme (planning scheme) has been
prepared in accordance with the <i>asdf </i>(the Act)
as a framework for managing development in a way that advances the purpose of
the Act.</h5>
<h5>(2)<span style='font:7.0pt "Times New Roman"'>
</span>In seeking to achieve this purpose, the planning scheme sets out
the future development in the
planning scheme area over the next 20 years.</h5>
<h5>(3)<span style='font:7.0pt "Times New Roman"'>
</span>While the planning scheme has been prepared with a 20 year horizon, it
will be reviewed periodically in accordance with the Act to ensure that it
responds appropriately to the changes of the community at Local, Regional and State
levels.</h5>
正規表現は機能しているように見えますが、最初のh5から最後のh6 | 7|8までキャプチャします。
私はここでデータを複雑にするために何もしようとはしていません。単純な抽出が必要なので、htmlパーサーを使用するのではなく、正規表現を使用したいと思います。私の例では、見出しは適切であると言っても過言ではありません。形成された、すなわち。hXは常にhYではなくhXによって閉じられ、見出しには見出しやそのようなファンキーなものはありません。
?を追加しようと思いました (?:)の終わりまでは、それを貪欲ではないので、最初のインスタンスにのみ一致し、可能な限り多くは一致しません。貪欲がどのように機能するかについて、ここで何かが欠けていますか?
編集:
正規表現
<(?<Class>h[5-8])>(?<ListIdentifier>.*?)<span style='font:7.0pt "Times New Roman"'>(?: )+.+?</span>(?<Text>.*?)(?:</h[5-8]>)
も一致するようです
<h6> </h6>
<h6> </h6>
<h6> </h6>
<h6> </h6>
<h5>(1)<span style='font:7.0pt "Times New Roman"'>
</span>Short Title -The planning scheme policy may be cited as PSP No 2. –
Engineering Standards – Road and Drainage Infrastructure.</h5>
したがって、テキスト全体が含まれますが、nbspを含むh6はスパンがないため、無視したいと思います。