Deye Posted September 28, 2019 Share Posted September 28, 2019 (edited) This one will be easy for some one who is with a fresh mind Local $__ItemPaths = 'C:\Users\user\Contacts\' & @LF & _ 'C:\Users\user2\Desktop\' & @CRLF & _ 'C:\Users\user' & @CRLF & _ 'C:\Users\user\Documents\' & @CRLF $sSearch = "C:\Users\user" $sOutput = StringRegExpReplace($__ItemPaths, "(\Q" & $sSearch & "\E([\\])\R)", "") MsgBox(0, '', $sOutput) All i need is it to replace-out the "C:\Users\user" instance if the instance in $__ItemPaths is with "\" as in "C:\Users\user\" .. should get it out in both cases Tried doing it with adding another group used with-without ([\\]) in the pattern .. still no luck Thanks Edit: Never Mind just Got something that worked : should be something like so: StringRegExpReplace($__ItemPaths, "(\Q" & $sSearch & "\E.?\R)", "") Edited September 28, 2019 by Deye Link to comment Share on other sites More sharing options...
Solution iamtheky Posted September 28, 2019 Solution Share Posted September 28, 2019 yours does open lots of edge cases, maybe something down this path... (but not this, because it too has many lackings). Local $__ItemPaths = 'C:\Users\user\Contacts\' & @LF & _ 'C:\Users\user2\' & @CRLF & _ 'C:\Users\user' & @CRLF & _ 'C:\Users\user\' & @CRLF & _ 'C:\Users\user2\stuff' $sSearch = "C:\Users\user" ;~ $sOutput = StringRegExpReplace($__ItemPaths, "(\Q" & $sSearch & "\E([\\])\R)", "") ; original $sOutput = StringRegExpReplace($__ItemPaths, "(\Q" & $sSearch & "\E\\*(?:\r|\z))", "") MsgBox(0, '', $sOutput) Deye 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Deye Posted September 28, 2019 Author Share Posted September 28, 2019 The groups syntax used with my testing was wrong .. should have tried : $sOutput = StringRegExpReplace($__ItemPaths, "(\Q" & $sSearch & "\E\R)|(\Q" & $sSearch & "\E\\\R)", "") Thanks @iamtheky Link to comment Share on other sites More sharing options...
seadoggie01 Posted September 30, 2019 Share Posted September 30, 2019 Does it really need to be a regular expression then? You could just use StringReplace (once without a trailing \ and once with) All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now