• Login
Community
  • Login

regex in balise html

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 729 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B
    broutin joel
    last edited by May 10, 2022, 1:50 PM

    hello after several searches I can’t find the regex that could remove the text between: <head> and </head>

    <head>
    dfgdfgdfg
    dfgdfg
    dfgdfg
    dfgdfg
    </head>

    thank you in advance

    P 1 Reply Last reply May 10, 2022, 2:14 PM Reply Quote 0
    • P
      PeterJones @broutin joel
      last edited by PeterJones May 10, 2022, 2:16 PM May 10, 2022, 2:14 PM

      @broutin-joel ,

      We have a FAQ entry on Generic Regex Formulas. The first link in that FAQ entry is Replacing in a specific zone of text. In your case, that “zone” would be the text between <head> and </head>. So you can easily translate those as the START (BSR) and END (ESR) sequences of the zone, as described in the link found in the FAQ.

      In your case, the FR (Find Regex) would be .*? for "find as little as possible; the RR (Replacement Regex) would be the empty string (because you wanted to “remove the text between”); the BSR (Begin Search-Region Regex) would be <head>; and the ESR (End Search-region Regex) would be </head>. Plug those into the formula given, et voila!

      Good luck.

      P 1 Reply Last reply May 10, 2022, 2:19 PM Reply Quote 0
      • P
        PeterJones @PeterJones
        last edited by May 10, 2022, 2:19 PM

        @broutin-joel ,

        Okay, the generic expression doesn’t work as well as I thought in situations like this when you want to replace everything between the start and end of a range, rather than just pieces.

        The easiest will be to just search for everything between <head> and </head>, with FIND = <head>(?s:.*?)</head> , REPLACE = <head></head>, MODE = regular expression

        B 1 Reply Last reply May 10, 2022, 2:24 PM Reply Quote 1
        • B
          broutin joel @PeterJones
          last edited by May 10, 2022, 2:24 PM

          @peterjones said in regex in balise html:

          <head>(?s:.*?)</head>

          thank you very much.

          1 Reply Last reply Reply Quote 0
          • R
            Robin Cruise
            last edited by Robin Cruise May 14, 2022, 6:57 PM May 14, 2022, 6:56 PM

            Regex: Select text between two tags/strings: You can try also:

            FIND: (?s)(<head>).*?(</head>)
            REPLACE BY: \1\2

            OR

            FIND: (<head>)\K[^>]*(?<!/)(</head>)|\1
            REPLACE BY: </head>

            OR

            FIND: (<head>)\K[\s\S]*?(</head>)|\1
            REPLACE BY: </head>

            1 Reply Last reply Reply Quote 0
            4 out of 5
            • First post
              4/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors