Community
    • Login

    regex in balise html

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 608 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.
    • broutin joelB
      broutin joel
      last edited by

      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

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @broutin joel
        last edited by PeterJones

        @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.

        PeterJonesP 1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @PeterJones
          last edited by

          @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

          broutin joelB 1 Reply Last reply Reply Quote 1
          • broutin joelB
            broutin joel @PeterJones
            last edited by

            @peterjones said in regex in balise html:

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

            thank you very much.

            1 Reply Last reply Reply Quote 0
            • Robin CruiseR
              Robin Cruise
              last edited by Robin Cruise

              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
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors