Community
    • Login

    2 Instances In Find & Replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 3.2k 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.
    • JayLaFunkJ
      JayLaFunk
      last edited by

      I would like to use Find & Replace with 2 instances, the first instance is straight forward,
      Find Z:\ Replace with /share/Public/

      I would like to introduce a second instance together with the first to all in one pass

      replace all the backward slashes to forward slashes
      Find \ Replace /

      Is there anyway to do this or will I have to do it in 2 different F&R

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello JayLaFunk,

        Easy enough, with the S/R, below, using the regular expression search mode :

        SEARCH = (?i)(Z:\\)|(\\) and REPLACE = (?1/share/Public/)(?2/)

        For instance, the two sentences, below :

        The absolute path : "C:\Program Files(x86)\7-zip\Lang"
        The network drive Z:\ contains some public software, for everybody
        

        are changed, in one go, into :

        The absolute path : "C:/Program Files(x86)/7-zip/Lang"
        The network drive /share/Public/ contains some public software, for everybody
        

        Notes :

        • The (?i) modifier force the insensitive behaviour of the regex engine, even if the match case option is set, in the replace dialog ( Just in case, your text contains the string z:\, with a lowercase drive letter ! )

        • The backslash character have a special meaning, in regexes. So, it must be escaped itself, with an other backslash character, to be taken, literally.

        • The search regex contains two groups : group 1 = Z:\\ and group 2 = \\, between round brackets.

        • The replace regex contains two conditional replacement groups : (?1/share/Public/), which writes the string /share/Public, if group 1 exists and (?2/), which writes a forward slash, if group 2 exists.

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • JayLaFunkJ
          JayLaFunk
          last edited by

          Cheers Guy, that worked a treat.

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