Jump to content

RegExp Replace Q


Deye
 Share

Go to solution Solved by iamtheky,

Recommended Posts

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 by Deye
Link to comment
Share on other sites

  • Solution

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)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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 functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...