Multi Commander > Script

Search routine

<< < (7/8) > >>

Ulfhednar:
I have begun looking at the MC regex function.
I wonder if this is not an acceptable regex -

--- Code: ---((?:[0-9]+)+)
--- End code ---
ie: -  find numbers, can be any number of numerals in a group.
Same for letters

--- Code: ---((?:[a-zA-Z]+)+)
--- End code ---

MC doesn't seem to accept this format. 
I see your example

--- Code: --- <str> StrRegExpReplace(<str>, <regex>, <replaceWith>, [int startPos] )
example

@var $str = "This.String.A02B22.SUBString-ZZZZ";
@var $re = ".A[0-9][0-9]B[0-9][0-9]."";
@var $result = StrRegExpReplace($str, $re, "XX");
 // result is This.StringXXSUBString-ZZZZ
--- End code ---

 - specifies quantity of individual characters.  'Hungry' expression is defined differently in MC?

For my experiment I had been thinking of changing a folder date format, e.g. :-
10-05-1989 -> 10.05.1989

--- Code: ---((?:[0-9]+)+)-((?:[0-9]+)+)   ->    ((?:[0-9]+)+).((?:[0-9]+)+)
--- End code ---
or
10_May_1989 -> 10 May 1989

--- Code: ---((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+) ((?:[0-9]+)+)
--- End code ---

   
I tried: -

--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $str = $OrgName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrRegExpReplace($str, $re, ".");
 
  RenameFile( $arr, $NewName, "SILENT" );
  }
--- End code ---

But I get - Error : -23 => Parameter wrong type or in the mass rename - 'invalid characters' msg
I had the regex's working  outside MC - but they don't work in the mass rename or the script (yet)   :-[


Mathias (Author):

--- Quote from: Ulfhednar on August 18, 2013, 15:29:31 ---I have begun looking at the MC regex function.
I wonder if this is not an acceptable regex -

--- Code: ---((?:[0-9]+)+)
--- End code ---

--- End quote ---
Don't know. I'm not a regex expert. I just use the regex libraries that is included in the C++11 standard and that regex engine should be mostly perl regex compatible

--- Quote from: Ulfhednar on August 18, 2013, 15:29:31 ---MC doesn't seem to accept this format. 
I see your example

--- Code: --- <str> StrRegExpReplace(<str>, <regex>, <replaceWith>, [int startPos] )
example

@var $str = "This.String.A02B22.SUBString-ZZZZ";
@var $re = ".A[0-9][0-9]B[0-9][0-9]."";
@var $result = StrRegExpReplace($str, $re, "XX");
 // result is This.StringXXSUBString-ZZZZ
--- End code ---

 - specifies quantity of individual characters.  'Hungry' expression is defined differently in MC?

--- End quote ---
Hungry ?  The above example works. It is takes from my automated unittests.


--- Quote from: Ulfhednar on August 18, 2013, 15:29:31 ---For my experiment I had been thinking of changing a folder date format, e.g. :-
10-05-1989 -> 10.05.1989

--- Code: ---((?:[0-9]+)+)-((?:[0-9]+)+)   ->    ((?:[0-9]+)+).((?:[0-9]+)+)
--- End code ---
or
10_May_1989 -> 10 May 1989

--- Code: ---((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+) ((?:[0-9]+)+)
--- End code ---

--- End quote ---
Don't think you can do that... because the matching regex will be replaced with the replaceWith string.
You can not replace with another regex.


--- Quote from: Ulfhednar on August 18, 2013, 15:29:31 ---I tried: -

--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $str = $OrgName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrRegExpReplace($str, $re, ".");
 
  RenameFile( $arr, $NewName, "SILENT" );
  }
--- End code ---

But I get - Error : -23 => Parameter wrong type or in the mass rename - 'invalid characters' msg
I had the regex's working  outside MC - but they don't work in the mass rename or the script (yet)   :-[

--- End quote ---
What row did it not like ?
Hmm should you not use $OrgName for StrRegExpReplace ?
And I guess the error is for RenameFile(..) You can still not send an entire array into that. first paramter should be a string that is the is full target path of the file.

if you get invalid char in multirename then you got an invalid char into the file name like :| or some other invalid character.

Ulfhednar:
I added a couple of screen shots above to help explain what is happening with mass rename & the regex's.
Debug error was row 13 then 14 when I used $Orgname

(I'm no expert I only know enough to cause trouble!) Hungry:- + forces regex engine to keep looking for matches so

--- Code: ---((?:[0-9]+)+)
--- End code ---
should find any combination of digits.  Useful for dates etc where you may have 1-12-1980

--- Code: --- ((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)
--- End code ---
should match that sequence.
In your example you predefined the # of digits with [0-9] [0-9], if it works with + you can (in theory!) match more than the 2 digits without defining multiple [0-9]s. 

If I use $Orgname I think I drop part of the sequence which links to $newname, maybe I need to have 2 {....} operations defined, one to run the regex, then the next to take the result & use it to rename.  ???

My bad  - I wasn't thinking replace regex with regex but how the groups would appear as a regex (trying out variations in mass rename & confusing myself!)

Thanks for your time Mathias.

Ulfhednar:

--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, ".");
 
  RenameFile( $arr, $result, "SILENT" );
 
  }
--- End code ---

Seems better - no errors but not renaming.  Will keep trying.

Update

--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = ".A[0-9][0-9]B[0-9][0-9].";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, ".");
 
  RenameFile( $arr, $result, "SILENT" );
 
  }
--- End code ---

changes
--- Code: ---"This.String.A02B22.SUBString-ZZZZ" ->  "This.String.SUBString-ZZZZ"
--- End code ---
...so the regex is definitely not MC friendly....  :'(
I will need to find out how this system handles the 'hungry' (greedy) operation ::)

As it is the regex I have used would match all combos of 1-12-123; 123-1-12; 1234-12-123 etc so it would be handy to transpose this into the MC-friendly form.

OT -
what do I do to access multiple selections?  At the moment this will only do the first of any selected group.  I'm guessing it's related to $n.

Update 2


--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "\d+";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, "x");
 
  RenameFile( $arr, $result, "SILENT" );
}
--- End code ---

Will change multiple digits but won't retain the initial sequence
1.23.234
becomes x.x.x

I want to pass the original string back modifying only certain characters. 
As in  eg -

--- Code: ---((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+)-((?:[0-9]+)+)
--- End code ---

10_May_1980 -> 10 May-1980

I suspect I'm not going to be able to do this.    :(

Mathias (Author):
The rename will never work because you are still using $arr in rename file. That will not work.

RenameFile($arr, $result, "SILENT" );

RenameFile(...) does not accept an array.. it wants a string.

What you trying to do will never work, you can not insert a regex in the replace with part. There is no way for it to match stuff like that.
There no way the engine should understand how match that.

Maybe use the StrRegExFind and from that you get at what position the regex match start. and from there you can get the substring and rebuild the string and replace the part you want manually.
Or you can also loop the string and check character by character and if  you find a - or _ of after a number you replace it.
But then you are not using any cool regexp.

Regex engine in MC is following the regex standard. Think it is called ECMA-262 .. What I understand it is the same as perl uses.
MC does not use any special own regex. it is build into the C++ language as of the C++11 Standard.
But regex are written different depending on what you want to do. and there are 100 ways to do the same thing.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version