[Solved] Regex path filename last delimiter

Discuss the spreadsheet application
Post Reply
User avatar
bertram
Posts: 12
Joined: Sat Mar 17, 2012 4:35 am

[Solved] Regex path filename last delimiter

Post by bertram »

want to find position of last \ delimeter in string for full filename (with path and extension), with unknown number of folders

typical string is in cell c5 -- m:\3_patches\Updates\Windows7-x64\Extra\Addons\FM.API\Windows6.1-KB943790-x64.msu

don't want string for the drivename or pathname or filename
just the position number of the last occurance of "\" delimiter

I've tried every combination permutation I can think of -- calc always retursn #value! error

Code: Select all

=FIND("^[^\\]+\\.?$",C5,1)
=FIND("^.+\\[^\\]?$",C5,1)
... etc
find
from beginning of string: ^
any char: .
with max greedy search intention: +
to last occurance of delimiter: \\
followed by any chars not a "\": [^\\]
with minimal search intention: ?
to end of string: $

in tools > options > calc > calculate : regular expressions in formulas are enabled

arghh!
somewhere I gone wrong -- help much appreciated
Last edited by Hagar Delest on Sat Jun 16, 2018 5:09 pm, edited 1 time in total.
Reason: tagged [Solved].
Platonic solids: constructed by modulation of rotational action -- the tetrahedron can be constructed by negentropic action of four bundles of rotational energy, where each bundle is quantized by modulation 3.
Windows XP pro SP3, LibreOffice 4.4.5.2
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: regex path filename last delimiter

Post by Lupp »

FIND() doesn't evaluate RegEx at all. Only literals. Use SEARCH() and make sure that RegEx in formulae are enabled.

Code: Select all

=SEARCH("\\[^\\]*$";C5)
Of course, this only works with Windows paths.

Code: Select all

=SEARCH("/[^/]*$";SUBSTITUTE(C5;"\";"/"))
should work system independent.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
bertram
Posts: 12
Joined: Sat Mar 17, 2012 4:35 am

Re: regex path filename last delimiter

Post by bertram »

thanks Lupp!

yes, this is windows delimiter for folders = \

this works

Code: Select all

=SEARCH("[^\\]*[^\\]+$",C5,1)
--- edit ---
ah yes, yours works better and is cleaner !! thanks!
Platonic solids: constructed by modulation of rotational action -- the tetrahedron can be constructed by negentropic action of four bundles of rotational energy, where each bundle is quantized by modulation 3.
Windows XP pro SP3, LibreOffice 4.4.5.2
Post Reply