Community
    • Login

    2 Instances In Find & Replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 3.9k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          JayLaFunk
          last edited by

          Cheers Guy, that worked a treat.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors