Sign in to follow this  
Followers 0
Izebize

[Solved] StringRegExp help

4 posts in this topic

#1 ·  Posted (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 by Izebize

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Whatever works for you. I'm just not used to regex as a replacement. I usually work on matches and groups not replacements.

Share this post


Link to post
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
Sign in to follow this  
Followers 0