"Copy Path" regexp transformation?
"Copy Path" regexp transformation?
So I have been using XY and Directory Opus for over a year now, and I find myself switching back and forth because each one has its specialty. I find XY to be orders of magnitude faster browsing linux network shares, which is what I spend mot of my time working with, so Id prefer using XY for as much as I can.
There is one thing Opus has that I just cant do without, and that is being to copy a file or folder name to the clipboard and have a regexp transform it to a unix-style path for pasting. For example, say i copy a folder that normally would put the text string "S:\usr\local\apache2\conf" into the clipboard. I am looking for something in XY that would automatically apply a regexp to that string to make it "/usr/local/apache2/conf" Does such a feature exist in XY?
There is one thing Opus has that I just cant do without, and that is being to copy a file or folder name to the clipboard and have a regexp transform it to a unix-style path for pasting. For example, say i copy a folder that normally would put the text string "S:\usr\local\apache2\conf" into the clipboard. I am looking for something in XY that would automatically apply a regexp to that string to make it "/usr/local/apache2/conf" Does such a feature exist in XY?
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!ryanagler wrote:For example, say i copy a folder that normally would put the text string "S:\usr\local\apache2\conf" into the clipboard. I am looking for something in XY that would automatically apply a regexp to that string to make it "/usr/local/apache2/conf" Does such a feature exist in XY?
PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...
Code: Select all
S:\usr\local\apache2\conf
/usr/local/apache2/conf
FAQ | XY News RSS | XY Twitter
Re: "Copy Path" regexp transformation?
/me gets all excited, takes note : v7.2admin wrote:There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
Proud XYplorer Fanatic
Re: "Copy Path" regexp transformation?
awesome!admin wrote:Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
There are some exceptions, but 90% of the time, yes! If you could add it that would be great!admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
90% is not enough. So, what RegExp do you use for this job?ryanagler wrote:awesome!admin wrote:Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
There are some exceptions, but 90% of the time, yes! If you could add it that would be great!admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...
FAQ | XY News RSS | XY Twitter
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
Okay, I added it right now.jacky wrote:/me gets all excited, takes note : v7.2admin wrote:There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??
FAQ | XY News RSS | XY Twitter
-
- XY Blog Master
- Posts: 5824
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: "Copy Path" regexp transformation?
I'd suggest: regexrpl ...or... regexrep as I think regex needs to be there.admin wrote:Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??
As I initially read regrep as re-grep...
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
Yep. I made a little research and found that "RegExReplace" is a quite common name for it, so I take it.j_c_hallgren wrote:I'd suggest: regexrpl ...or... regexrep as I think regex needs to be there.admin wrote:Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??
As I initially read regrep as re-grep...
It will look like this:
Code: Select all
RegExReplace OutputVar, InputString, RegExPattern, Replacement, MatchCase
FAQ | XY News RSS | XY Twitter
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
v6.80.0112 can do this now. Create a UDC "Run Script" and use the following multiline script (use Edit... button to enter it):admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...Code: Select all
S:\usr\local\apache2\conf /usr/local/apache2/conf
Code: Select all
// copy current item as unix path
mid $p, <curitem>, 3;
replace $p, $p, "", "/";
copytext $p;
PS: why was I so keen to add it already now? Because now I can do this:
Code: Select all
// copy current item as xyplorer.com URL
replace $p, <curitem>, "", "/";
replace $p, $p, "D:/www/xyplorer.com/code", "http://www.xyplorer.com";
copytext $p;
FAQ | XY News RSS | XY Twitter
Re: "Copy Path" regexp transformation?
Awesome!!admin wrote:Okay, I added it right now.jacky wrote:/me gets all excited, takes note : v7.2
Haven't played with it much, but I couldn' resist a few tries... I have a question though : it seems that caret (^) & dollar ($) only match the very start and very end of the entire string, I think it'd be better if it could match the beginning & end of every line instead (or at least add an option to switch to this mode).
(On your end, I beleive all it takes is to put Multiline to True.)
PS: this is pretty cool stuff!!
Proud XYplorer Fanatic
-
- Site Admin
- Posts: 60558
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: "Copy Path" regexp transformation?
Okay, done. All wishes should be that easy!jacky wrote:(On your end, I beleive all it takes is to put Multiline to True.)
FAQ | XY News RSS | XY Twitter
Re: "Copy Path" regexp transformation?
Cool, thanksadmin wrote:Okay, done. All wishes should be that easy!jacky wrote:(On your end, I beleive all it takes is to put Multiline to True.)
So, couple of (quick) suggestions that seems to come naturally...
- mid : might be nice to have <start> to support negative values, to start from the end, so mid $a, "Maxi", -2 would return "xi"
- locate : returns the position on a string. locate $i, "Maxi", "a" would return 2
- inc : to increment an integer value. set $a, 2; inc $a, 3; msg $a; inc $a, -7; msg $a; would say "5" the first time, and "-2" the second time
- regexp : to use a regexp to search/extract a string, so regexp $a, "C:\Folder\Sub\Here", ":\\(.+?)\", "Main folder is $1" would return "Main folder is Folder"
Proud XYplorer Fanatic
Some notes from me, too...
On "SubStr", the very last character is addressed by Start = -1, while the very first is Start = 0. I wouldn't really expect this.
(And on a string-instruction in a script I would prefer to count the first char as 1 - I don't think of an offset here, but of a position in the string?)
Isn't the "Incr"-instruction "Add"? It adds second and third operand, and returns result as the first?
(Only, if you don't plan to define "Set result, var1+var2+var3" or so. But I don't expect that...)
Is there a reason to limit "AddStr" to 3 variables? Some more could be quite handy. (While 3 will do in most cases...)
For "functions" requiring a number (like a pos, length, ...): what happens, if it is alfa or so?
But one thing must be said: the abilities of scripting are enhanced by these few variable-manipulating instructions by a whole world!
Enjoy your bootcamp, or how did you call it
On "SubStr", the very last character is addressed by Start = -1, while the very first is Start = 0. I wouldn't really expect this.
(And on a string-instruction in a script I would prefer to count the first char as 1 - I don't think of an offset here, but of a position in the string?)
Isn't the "Incr"-instruction "Add"? It adds second and third operand, and returns result as the first?
(Only, if you don't plan to define "Set result, var1+var2+var3" or so. But I don't expect that...)
Is there a reason to limit "AddStr" to 3 variables? Some more could be quite handy. (While 3 will do in most cases...)
For "functions" requiring a number (like a pos, length, ...): what happens, if it is alfa or so?
But one thing must be said: the abilities of scripting are enhanced by these few variable-manipulating instructions by a whole world!
Enjoy your bootcamp, or how did you call it
As Don said, it goes along with the substr function of PHP. It is common usage, so it makes sense to find it here in XY as well.PeterH wrote:On "SubStr", the very last character is addressed by Start = -1, while the very first is Start = 0. I wouldn't really expect this.
(And on a string-instruction in a script I would prefer to count the first char as 1 - I don't think of an offset here, but of a position in the string?)
As hinted in a few examples, if the first characters of the string are numbers, their value will be used, otherwise zero.PeterH wrote:For "functions" requiring a number (like a pos, length, ...): what happens, if it is alfa or so?
"foo" => 0
"foo2" => 0
"2foo3" => 2
Agreed!PeterH wrote:But one thing must be said: the abilities of scripting are enhanced by these few variable-manipulating instructions by a whole world!
BTW, the next logical step here now (but for after v7.0 of course) has to be condition (IF..THEN..ELSE..) and loops (WHILE), right?
Proud XYplorer Fanatic
I'm afraid there are a lot of systems, some count strings from position 0, some from pos 1. Wouldn't it be best to take the better version - whatever? And I wouldn't have posted my question, if there wouldn't be the discrepancy of 1 = 2nd character, but -1 = 1st character from the end. So if 0 is the first char, I would ask for -0 to be the last char...jacky wrote:As Don said, it goes along with the substr function of PHP. It is common usage, so it makes sense to find it here in XY as well.
Thanks for the info about mis-formatted numbers, very usefull to know what to expect.
And yes: If...Then...Else... and some kind of loop (like I said above: different systems have different commands, like While, For, Do, ...). But what I also would like to see are Do...End groups. (Some use Begin...End instead, don't know what PHP does...)