Regex: trova quei particolari tag html che contengono queste parole (stringhe)
Ho questo tag:
<span class="text_obisnuit2">* Notă:</span>John Wells - <em>My Dreams</em>, Albatros Books, 1986.</p>
e questo:
<span class="text_obisnuit1">* Notă:</span>Mariah Carey - <em>Lovers on the road</em>, BackStreet Books, 1965.</p>
Quindi, voglio trovare quei particolari tag html <span class="text_obisnuit2">
che contengono queste parole (stringhe): Albatros
e <em>
e </em>
(La prima riga)
Risposte
Questo è semplice, ma richiede che "Albatros" venga dopo il <em>
tag ( demo ):
(<span class="text_obisnuit2">).*<em>.*<\/em>.*Albatros.*
Il seguente non interessa in quale ordine sono ( demo ):
(<span class="text_obisnuit2">).*(<em>.*<\/em>.*Albatros.*|Albatros.*<em>.*<\/em>.*)
Ecco un'altra variazione, in cui le cifre dopo text_obisnuit
non contano e l'intero span
tag viene catturato come primo gruppo ( demo ):
(<span class="text_obisnuit\d+">.*<\/span>).*(<em>.*<\/em>.*Albatros.*|Albatros.*<em>.*<\/em>.*)
Tutte le espressioni regolari presumono che le voci siano ciascuna sulla propria riga nel file. Forse ha più senso rilevare per <p>
e </p>
come i confini, ma per questo avremmo bisogno di un estratto più grande dal tuo file di input.
- Ctrl+F
- Trovare cosa:
<span class="text_obisnuit2">(?=.*?<em>.*?</em>)(?=.*?\bAlbatros\b).*$
- CONTROLLA Avvolgere
- CONTROLLA Espressione regolare
- UNCHECK
. matches newline
- Find All in Current Document
Spiegazione:
<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
Immagine dello schermo:
