Jump to content
Ketarin forum

Regexreplace not 100%


FranciscoR
 Share

Recommended Posts

Regexreplace: Replaces the content matched with the regular expression (first argument) with the second argument. The second argument may contain $n as references to groups of the regular expression. http://cdburnerxp.se/help/kb/20

'May' contain $n or 'need' to contain $n ?

{var:regexreplace:[^a-z]:.?}

 

Doesn't work; and as far as i can understand (trial-n-error testing),

{var:regexreplace:([a-z]+)[^a-z]:$1.?}

 

replaces only the *first* match group, so if i have a filename starting with 'Firefox_Portable_' or '7-Zip_Portable_' doesn't work either. So how can i replace that into something like '7.?Zip.?Portable.?' ?

 

{var:regexreplace:([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]:$1.?$2.?$3.?}

 

This is really complicated :( the regex i actually have to use with this function is

(?-s:{var:regexreplace:([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]:$1.?$2.?$3.?}(\d+(?:\.\d+)+.*?)(?:\.paf\.exe))

 

Otherwise funtion will span through several lines of code => ERROR. So, can't we improve/simplify this function ?

 

1.Couldn't we replace ALL matches of each match group?

 

2.Couldn't we make $n optional ?

 

3.BTW, any specific reason for this function to be case-sensitive ? This is a bit confusing.

 

--------------------------------

Edited by FranciscoR
Link to comment
Share on other sites

Update: i've found a way to test this:

 

{appname:regexreplace:[^A-Za-z]:.?}

14-06-2009 19:12:20: SF_Firefox_Portable-Minefield: Determined target file name: D:\Programas\Internet\SF.?Firefox_Portable-Minefield_3.0.11.exe

 

Not working, only the first replacement is done.

{appname:regexreplace:([A-Za-z]+)[^A-Za-z]:$1.?}

14-06-2009 19:18:08: SF_Firefox_Portable-Minefield: Determined target file name: D:\Programas\Internet\SF.?Firefox_Portable-Minefield_3.0.11.exe

 

Not working either, same problem as above (and result).

 

{appname:regexreplace:([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]([A-Za-z0-9]+)[^A-Za-z0-9]:$1.?$2.?$3.?}

14-06-2009 19:20:10: SF_Firefox_Portable-Minefield: Determined target file name: D:\Programas\Internet\SF.?Firefox.?Portable.?Minefield_3.0.11.exe

 

This one works as expected. Not the best solution, hardly practical.

 

 

In conclusion, this is #1 request only: to replace ALL matches of each match group.

Link to comment
Share on other sites

> 1.Couldn't we replace ALL matches of each match group?

 

Will do that for the next version.

 

> 2.Couldn't we make $n optional ?

 

It is.

 

> 3.BTW, any specific reason for this function to be case-sensitive ? This is a bit confusing.

 

It just gives you more possibilities.

Link to comment
Share on other sites

Thanks Flo,

 

> 2.Couldn't we make $n optional ?

 

It is.

 

Yep, i see now. Perfect !

 

> 3.BTW, any specific reason for this function to be case-sensitive ? This is a bit confusing.

 

It just gives you more possibilities.

 

Ok, maybe you could add 'this function is case-sensitive' to description ?(not a big deal, just because we are used to case-insensivity regexes in Ketarin =))

Edited by FranciscoR
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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.