-2

I have this 3 situation in which I have <em> and </em> html tags framed by <p class="TATA"></p> class

First case: (1 <em> and 1 </em> anywhere in the tag)

<p class="TATA">Ou quand vous peignez une fleur, comment elle ouvre ses pétales et montre <em>sa me dans </em> grâce dans votre jardin.</p>

Second case: (2 <em> and 2 </em> anywhere in the tag)

<p class="TATA"><em>Une fleur est un accompagnement <em>je veux aimer quelqu'un mais </em> je ne peux pas à cause du virus.</em></p>

The Third Case (1 <em> at begin and 1 </em> at the end of the tag)

<p class="TATA"><em>Une fleur est un accompagnement.</em></p>

The problem: I want to find only those <p class="TATA"></p> tags that contains other <em> and </em> except for those found at the beginning and end of the tag.

So The Output should find those files that contains 2 <em> and also 2 </em> . How can I do the search?

My regex is not very good, it find exactly the opposite (the second case).

FIND: (?:<p class="TATA">|\G(?!^))<em>\K.*?</em>(?=.*?</p>)

Can anyone help me?

7
  • 1
    This is confusing.  You have accepted an answer that will find <p class="TATA"><em>…the <em>lazy</em> dog.</em></p>; I interpreted the question as meaning that you didn’t want those.  Or are you saying that that case will never occur?  Why do you enumerate three cases and then not refer to them when you say what result you want?  And, since you seem to want to find cases 1 and 2, how is finding only case 2 “exactly the opposite” of what you want? Jun 1, 2021 at 23:52
  • hello @Scott. Yes, @harrymc helped me with 2 different cases. But later I noticed that he omitted an element /, so I correct that element. It's too late to enumerate. You've already rushed to give me negative votes. Please learn to explain to the person what needs to be corrected first, and then give him negative votes...
    – user706401
    Jun 2, 2021 at 13:13
  • (1) As you know, you can edit your own post at any time.  I know that you know that, because you have already edited your question twice (and also you’ve edited harrymc’s answer).  So why do you say “It's too late”?  (2) As you should know by now, downvotes are often not accompanied by explanations.  Perhaps you should thank me for commenting.  (3) Also, please learn that downvotes can be withdrawn — but only after the post has been improved.  (4) I see, by looking at the revision history of the question, that it is even more of a train wreck than I had previously realized.  … (Cont’d) Jun 4, 2021 at 18:36
  • (Cont’d) … (4a) It started with two cases, and you said (paraphrasing) «My regex finds the second case, which is exactly the opposite of what I want.» Then you renamed the second case to be the third case and created a new second case, and yet you left the statement about “the second case” untouched, even though your other edits reversed its meaning. (4b) And, in your first edit, you said the output should find those files that contains first and second case, only to take that out in the next edit. That’s exactly the sort of reference I asked you for; why did you delete it?  … (Cont’d) Jun 4, 2021 at 18:36
  • (Cont’d) … (5) In case you can’t see this, somebody has voted to close your question because it “needs details or clarity”.  Warning: I am inclined to agree.  I will probably add my vote to close next time I see it if it isn’t improved.  Hints: (5a) You could make the question clearer by adding words like “and”, “but not”, “exactly” and “only”.  (5b) And it would be good it you clarified whether your input can be malformed, and, if it can, how you want it handled.  For example, the first revision of the question … (Cont’d) Jun 4, 2021 at 18:36

1 Answer 1

0

I think that your regex is overly complicated, unless I have misunderstood the problem.

For me this is enough: <p class="TATA">.+<em>.+</p>

It searches for this tag when it contains <em> that is not immediately following the tag.


To find those <p class="TATA"> that contains 2 <em> tags, use:

<p class="TATA">.+<em>.+<em>.+</p>
3
  • almost perfect @harrymc I forgot once case. If I want to find those <p class="TATA"> that contains 2 <em> and also 2 </em> . How can I do the search?
    – user706401
    Jun 1, 2021 at 11:57
  • 1
    Similar: <p class="TATA">.+<em>.+<em>.+</p>.
    – harrymc
    Jun 1, 2021 at 12:33
  • thanks a lot @harrymc
    – user706401
    Jun 1, 2021 at 12:44

You must log in to answer this question.