0

I want to find all the files in which there is no class like that contains the word "neculaifantaru"

I have these 2 html same classes:

<p class="mb-40px">I must go home, but I don't know the road.</p>
<p class="mb-40px">I love myself , because I love nature.</p>
<p class="mb-40px">Cercetare estetică, care poartă <a href="https://neculaifantanaru.com/en/qualities-of-a-leader.html" class="color-bebe" target="_new">lumina artei</a> sinestezice</p>

The output must be:

<p class="mb-40px">I must go home, but I don't know the road.</p>
<p class="mb-40px">I love myself , because I love nature.</p>

My regex is not very good:

(?-si:<p class="mb-40px">|(?!\A)\G)(?s-i:(?!</p>).)*?\K(?-si:?!neculaifantanaru)

In Python it is easy. But I need a regex to do the same:

import os
import re

# Calea către directorul în care doriți să căutați
cale_director = 'g:/1/GATA ro'

# Parcurgeți toate fișierele din director
for nume_fisier in os.listdir(cale_director):
    cale_fisier = os.path.join(cale_director, nume_fisier)

    # Deschideți fiecare fișier și citiți conținutul acestuia
    with open(cale_fisier, 'r') as fisier:
        continut = fisier.read()

        # Căutați toate tagurile <p class="mb-40px">.*?</p>
        taguri_p = re.findall(r'<p class="mb-40px">(.*?)</p>', continut, re.DOTALL)

        # Verificați dacă există vreun tag care conține cuvântul "neculaifantanaru"
        tag_cu_neculaifantanaru = any('neculaifantanaru' in tag for tag in taguri_p)

        # Verificați dacă nu există niciun tag care să conțină cuvântul "neculaifantanaru"
        if not tag_cu_neculaifantanaru:
            print(f'Fișierul "{nume_fisier}" nu conține niciun tag <p class="mb-40px"> care să includă cuvântul "neculaifantanaru".')
2
  • If you are familiar with Python I suggest an installation of the Notepad++ Python Script plugin. Commented Jul 12, 2023 at 15:44
  • yes, I have installed notepad++. And I need a regex for Ruby Commented Jul 12, 2023 at 15:59

2 Answers 2

0

Try this, it works.

FIND: (?s)\A(?!.*(neculaifantanaru).*$)

...If it is not necessary to integrate between <p class="mb-40px"> and </p>

0
  • Ctrl+H
  • Find what: <p class="mb-40px">(?:(?!</p>).)*neculaifantanaru.*?</p>\R?
  • Replace with: LEAVE EMPTY
  • TICK Wrap around
  • SELECT Regular expression
  • TICK . matches newline
  • Replace all

Explanation:

<p class="mb-40px">     # literally
(?:                     # non capture group
    (?!                     # negative lookahead, make sure we haven't </p> after
        </p>                    # literally
    )                       # end lookahead
    .                       # any character
)*                      # end group, may appear 0 or more times
neculaifantanaru        # literally
.*?                     # 0 or more any character, not greedy
</p>                    # literally
\R?                     # optional line break

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

2
  • the opposite was needed. I had to find all the lines, except those containing "neculaifantaru" Commented Jul 12, 2023 at 16:42
  • @HellenaCrainicu: The result of my proposition is exactly what you expected in your question. This seems to be an XY problem. What are you trying to do?
    – Toto
    Commented Jul 12, 2023 at 17:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .