1

I want to Find all lines starting with a specific tag and ending with a different tag. For example:

<p class="amigo">My mother is at home.<br>

tried a regex, but doesn't work to good, because the selection does not stop at <br>, it selects all after it, if I have more tags like this: .*<p class="amigo">(?s)(.*)<br>*$

Can anyone help me?

0

2 Answers 2

2

Just make the wildcard not greedy:

<p class="amigo">(?s)(.*?)<br>
//               here __^

Edit according to comment:

  • Ctrl+F
  • Find what: <p class="amigo">(?:(?!</?p).)*<br>
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • CHECK . matches newline
  • Search in document

Explanation:

<p class="amigo">   # literally
(?:                 # start non capture group
    (?!</?p)        # negative lookahead, make sure we haven't "<p" or "</p"
    .               # 1 anycharacter
)*                  # end group, may appear 0 or more times
<br>                # literally

enter image description here

2
  • not quite, if I have something like this, doesn't work, it selects all tags/lines. <p class="amigo">My mother is at home.</p> <p class="amigo">My mother is at home.</p> <p class="amigo">My mother is at home.<br>
    – Just Me
    Commented Dec 20, 2018 at 13:12
  • @JustMe: See my edit.
    – Toto
    Commented Dec 20, 2018 at 13:54
0

also, I find another answer:

<p class="amigo">(?s)(?-s)(.*)<br>*$

or

<p class="amigo">(?-s)(.*)<br>*$

6
  • (?s) means "dot matches newline" and (?-s) nmeans the opposite "dot doesn't match newline. So, (?s)(?-s) is the same that (?-s) for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags. >*$ means 0 or more > before end of line. It is useless here.
    – Toto
    Commented Dec 20, 2018 at 17:49
  • I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
    – Just Me
    Commented Dec 20, 2018 at 20:00
  • Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
    – Toto
    Commented Dec 21, 2018 at 9:43
  • hello, yes. But what exactly means "match new lines" ?
    – Just Me
    Commented Dec 21, 2018 at 12:01
  • It means that . matches newline (\r,\n). The default behaviour is . doesn't match newline.
    – Toto
    Commented Dec 21, 2018 at 12:36

You must log in to answer this question.

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