• Login
Community
  • Login

Match and replace specific word between two tag symbol

Scheduled Pinned Locked Moved General Discussion
2 Posts 2 Posters 2.0k 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.
  • J
    Jade Owen
    last edited by Feb 11, 2018, 6:35 PM

    Hi,
    I’m trying to rename a specific word within tag symbol and i just cant figure it out and already tried looking on examples but still I’m stuck. Kindly please help.

    Example: I want to rename the word “LOCAL” to “SPACE” but only within <div>xx…xx</div>.
    <div>xxMETADATA-LOCALX1-ROOMG1-LEVELB2xx</div>
    <div class=“metadata”>METADATA-LOCALX1-ROOMG1-LEVELB2</div>

    Expected Result:
    <div>xxMETADATA-LOCALX1-SPACEG1-LEVELB2xx</div>
    <div class=“metadata”>METADATA-LOCALX1-ROOMG1-LEVELB2</div>

    Thank you very much.

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Feb 14, 2018, 6:41 PM Feb 14, 2018, 6:25 PM

      Hello, @jade-owen,

      I’m a bit perplexed ! Indeed, from your example, it looks as you would change the upper-case string ROOM with the upper-case string SPACE, when within a <div>.......</div> range, only… and NOT the LOCAL string !!

      If it’s really what you want, the regex, below, should do the job, strictly !

      SEARCH (?-is)(<div>.*?LOCAL..-)(.*?)(?=..-.*?</div>)

      REPLACE \1SPACE

      OPTIONS Tick the Wrap around and Regular expression options

      ACTION Click, once, on the Replace All button, or several times on the Replace button

      Best Regards,

      guy038

      P.S. :

      Generally speaking, it’s important to point out that regexes are very dependent of the text they are applying against ! Even a simple additional space character, in a text, can break out matches detection of a well-formed regex !

      So, I advice everyone, which wants a specific search/replacement, to carefully describe :

      • The searched text which must be matched

      • The replacement text which will be inserted, instead

      Doing this way should help out to build the right regex(es) and assures you to get a quicker solution, too ;-))

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