2 Instances In Find & Replace



  • 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



  • 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



  • Cheers Guy, that worked a treat.


Log in to reply