1

I have this 4 lines, all starting with tag <p class="TEST"> and ending with tag <br> except the last two.

<p class="TEST">My mother is at home.<br>
<p class="TEST">My father is at home.<br>
<p class="TEXT">My sister is at home.<LLbr>
<p class="TEXT">My brother is at home.<AAbr>

So, I want to find all lines with TEXT tag that doesn't ending with <br>

My output result should be

<p class="TEXT">My sister is at home.<LLbr>
<p class="TEXT">My brother is at home.<AAbr>

I made a regex, but is not too good. (?-s)(.*<p class="TEXT">.*)(?-s)(?!)<br>(.*)$

2
  • One option, that might give you what you want. If you Ctrl-F to bring up the search dialog, then click on the Mark tab. Check the Bookmark line option and search for <br> or whatever you need to mark the line. Then go to Search - Bookmark and select inverse bookmark. I find this workflow helpful in many scenarios. Hope it helps. Commented Dec 27, 2018 at 22:42
  • I have more than 5000 .html files to check :) I don't have time to check each individually :)
    – Just Me
    Commented Dec 28, 2018 at 10:11

1 Answer 1

3
  • Ctrl+H
  • Find what: <p class="TEXT">(?:(?!<br>)(?!<p).)*(?:<.+?>|\z)
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • UNCHECK . matches newline
  • Search in document

Explanation:

<p class="TEXT">    # literally
(?:                 # start non capture group
  (?!<br>)          # negative lookahead, make sure we haven't <br>
  (?!<p)            # negative lookahead, make sure we haven't <p
  .                 # any character but newline
)*                  # group may appear 0 or more times
(?:                 # non capture group
   <.+?>            # a tag
 |                  # OR
   \z               # end of string
)                   # end of group

enter image description here

DEMO

10
  • hello Toto, thanks a lot. But, another scenario.Suppose the <br> tag is on the next line, and I don't want to find also this because has <br>. See this link regex101.com/r/vSfrsv/2
    – Just Me
    Commented Dec 28, 2018 at 14:29
  • @JustMe: See updated demo
    – Toto
    Commented Dec 28, 2018 at 15:48
  • thank you, Toto. Please, update your answer with this alternative regex solution here, in case anyone need it. And also, please explain what means this part of regex: (?!<p).)*(?:<.+?>|\z)
    – Just Me
    Commented Dec 28, 2018 at 16:42
  • @JustMe: edit done.
    – Toto
    Commented Dec 28, 2018 at 17:01
  • please see this real case. regex101.com/r/y8GB6e/1 I change a little bit your regex, with my real tags. But is not working. Please help me, and change the good version on the link below. Instead of <br> I have </p>
    – Just Me
    Commented Dec 28, 2018 at 19:05

You must log in to answer this question.

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