正規表現:これらの単語(文字列)を含む特定のhtmlタグを検索します
Aug 19 2020
私はこのタグを持っています:
<span class="text_obisnuit2">* Notă:</span>John Wells - <em>My Dreams</em>, Albatros Books, 1986.</p>
そしてこれ:
<span class="text_obisnuit1">* Notă:</span>Mariah Carey - <em>Lovers on the road</em>, BackStreet Books, 1965.</p>
だから、私<span class="text_obisnuit2">
はこれらの単語(文字列)を含むそれらの特定のhtmlタグを見つけたいです:Albatros
そして<em>
そして</em>
(最初の行)
回答
4 Glorfindel Aug 19 2020 at 16:49
これは簡単なものですが、<em>
タグの後に「アルバトロス」が必要です(デモ)。
(<span class="text_obisnuit2">).*<em>.*<\/em>.*Albatros.*
次のものは、それらがどの順序であるかを気にしません(デモ):
(<span class="text_obisnuit2">).*(<em>.*<\/em>.*Albatros.*|Albatros.*<em>.*<\/em>.*)
これは別のバリエーションで、後の数字text_obisnuit
は重要ではなく、span
タグ全体が最初のグループとしてキャプチャされます(デモ)。
(<span class="text_obisnuit\d+">.*<\/span>).*(<em>.*<\/em>.*Albatros.*|Albatros.*<em>.*<\/em>.*)
すべての正規表現は、エントリがそれぞれファイル内の独自の行にあることを前提としています。おそらくそれはを検出するために、より理にかなっている<p>
と</p>
の境界として、それのために、私たちはあなたの入力ファイルから大きな抜粋を持っている必要があります。
4 Toto Aug 19 2020 at 17:01
- Ctrl+F
- 何を見つける:
<span class="text_obisnuit2">(?=.*?<em>.*?</em>)(?=.*?\bAlbatros\b).*$
- チェック ラップアラウンド
- CHECK 正規表現
- チェックを外す
. matches newline
- Find All in Current Document
説明:
<span class="text_obisnuit2"> # literally
(?= # positive lookahead, make sure we have after:
.*? # 0 or more any character but newline, not greedy
<em> # literally open em tag
.*? # 0 or more any character but newline, not greedy
</em> # literally close em tag
) # end lookahead
(?= # positive lookahead, make sure we have after:
.*? # 0 or more any character but newline, not greedy
\bAlbatros\b # Albatros with word boundaries
) # end lookahead
.* # 0 or more any character but newline
$ # end of line
スクリーンショット:
