Izebize Posted July 28, 2009 Posted July 28, 2009 (edited) $fFile = "X:\Folder\Archive.part1.rar" ConsoleWrite(StringRegExpReplace($fFile, ".*\\(.*)(?:\.part1)\.rar", "$1")&@CR) ;Works fine ConsoleWrite(StringRegExpReplace($fFile, ".*\\(.*)(?:\.part1)?\.rar", "$1")&@CR);keeps "part1" I want to set the ".part1" section may or may not appear. I thought this is the correct syntax, but It doesn't works. Edited August 11, 2009 by Izebize
Richard Robertson Posted July 28, 2009 Posted July 28, 2009 You used .* which is greedy. It is picking up everything it can. You can instead do a StringInStr match to see if it contains .part1 and remove it with the regex. This would be a simpler option.
Izebize Posted July 29, 2009 Author Posted July 29, 2009 Thanks for your help! I used StringInStr as you suggested, but now I figured out how to make it work with RegExp: $fFile = "X:\Folder\Archive.part1.rar" ConsoleWrite(StringRegExpReplace($fFile, ".*\\(.*)(?:\.part1)\.rar", "$1") &@CR);Old one ConsoleWrite(StringRegExpReplace($fFile, ".*\\(.*?)(?:\.part1)?\.rar", "$1") &@CR);Working one"?" is very important in these cases.
Richard Robertson Posted July 29, 2009 Posted July 29, 2009 Whatever works for you. I'm just not used to regex as a replacement. I usually work on matches and groups not replacements.
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