• Login
Community
  • Login

Regex: How to replace the content of a tag

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 1.4k 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.
  • V
    Vasile Caraus
    last edited by Feb 3, 2018, 2:54 PM

    hy. I want to math all the words that end with “!” from this tag:

    <title>Why I love! you so much</title>

    In this case, I want to match the word love! because has an !

    Now, I made this beautiful regex:

    (?-s)(<title>)*\w+!(?!\w*;)(?=[^<]*</title>)

    Now, I want to use this regex, to replace in several .html files all those tags that has ! Basicaly, I want to delete them from these tag. I try to replace ! wih an emptyspace, like so:

    Search: (?-s)(<title>)*\w+!(?!\w*;)(?=[^<]*</title>)
    Replace by: \1\2(LEAVE EMPTY)

    But doesn’t work. Can anyone help me?

    1 Reply Last reply Reply Quote 0
    • V
      Vasile Caraus
      last edited by Feb 3, 2018, 3:00 PM

      After replace, My tag should loook like:

      <title>Why I love you so much</title> (without !)

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by Feb 4, 2018, 10:24 AM

        Hello @vasile-caraus,

        I think that your regex S/R is excessively complicated ! Why not trying this simple one :

        SEARCH (?i)(?<=\w)!(?=\x20)

        REPLACE Leave EMPTY

        So, this search regex would match any ! symbol, which is, both :

        • Preceded by a word character, whatever its case, due to the (?i) modifier

        • Followed by a space character

        and would be deleted, as the replacement zone is empty !

        Cheers,

        guy038

        1 Reply Last reply Reply Quote 0
        • V
          Vasile Caraus
          last edited by Feb 5, 2018, 6:32 AM

          Search: (?:\G(?!^)|<title>)[^<]*?\K\b!\B

          Replace by: (leave a space)!

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