Page 1 of 1

EditPad regex Help

Posted: 29 Sep 2018 20:35
by SkyFrontier
Hi again.

How do I regex a filename so the files themselves are erased leaving paths only behind, with trailing '\'s? TIA!

As a general rule, the rightmost element of the last '\' can be considered as a file, even if it's lacking any extension or it's actually a folder.

Inputs:
c:\my\path\file.exe
d\another\random\path\_item

Outputs:
c:\my\path\
d\another\random\path\

Re: EditPad regex Help

Posted: 29 Sep 2018 21:01
by Marco

Code: Select all

^.*\\(?=.*?$)

Re: EditPad regex Help

Posted: 29 Sep 2018 21:10
by SkyFrontier
Hi, Marco, thanks for popping out.

It's producing the opposite, ie, taking out the paths, leaving the files behind.

Tried

Code: Select all

(^.*\\)?=.*?$
just to have some random mess.


In a variant task, I'd need to have just the parent folders as outputs. Please?
Inputs:
c:\my\path\file.exe
d\another\random\another path\_item

Outputs:
path
another path

Regards - and congrats for the awesome Archive!

Re: EditPad regex Help

Posted: 29 Sep 2018 22:22
by Marco
SkyFrontier wrote: It's producing the opposite, ie, taking out the paths, leaving the files behind.
So you don't want to match the paths, you want to replace with nothing (aka remove) the files? Subtle difference :ninja: ... With the regex I gave you then you could click on "Copy matches" to have those paths. If you want to zap instead the filenames, then use this

Code: Select all

[^\\]*?$
, leaving the Replace box empty.

For the other task, use this

Code: Select all

(?<=^.*\\)[^\\]+?(?=\\[^\\]+?$)
to match the parent folders. Choose this route, instead of deleting the rest.

Re: EditPad regex Help

Posted: 29 Sep 2018 22:41
by SkyFrontier
Hi, Marco. First task done.

But again - the other code is matching parent folders, thus replacing them by nothing; I need the other way round! :titter:

See...?

Code: Select all

Inputs:
c:\my\path\file.exe
d\another\random\another path\_item

Outputs:
path
another path
...or is it something I should change in replacement GUI I am missing...?

Re: EditPad regex Help

Posted: 30 Sep 2018 01:22
by Marco
I told you that that regex matches the parent folders! I don't understand, if you need the parent folders, why you insist on deleting the rest? Copy the matches!

Re: EditPad regex Help

Posted: 30 Sep 2018 02:22
by SkyFrontier
...didn't know I could do it that way, sorry... :roll:
Old dog got a new trick, thanks!

Re: EditPad regex Help

Posted: 30 Sep 2018 02:32
by SkyFrontier
Downside of this method: way too slow compared to the regular '-del-right-on-the-document', when exporting to the clipboard from a 200 MB source file.

...waaaaaaaay too slow.