04-13-2010 06:17 AM
I am trying to be clever (always a dangerous thing) and use a regular expression to extract the name of a library from a filepath converted to a string. Whilst I appreciate there are other ways to do this, regex would appear to be a very powerful neat way, should I be able to get it to work.
i.e if I have a string of the type, C:\applications\versions\library.llb\toplevel.vi, I want to be able to extract library.llb from the string, given that it will be of variable length, may include numbers & spaces and may be within a file hierarchy of variable depth. In other words, I want to extract the portion of the string between the last \ that ends with .llb
The best I have managed so far, is \\+.*llb which returned everything minus the drive letter and the toplevel.vi
Can anyone help me achieve this, or am i better using an alternative method (e.g filepath to array string, search for .llb)
Thanks
Matt
Solved! Go to Solution.
04-13-2010 06:30 AM - edited 04-13-2010 06:30 AM
Hi Matt,
attached you'll find two other options.
Mike
04-13-2010 07:14 AM
Thanks Mike.
I sometimes get distracted by trying to create 'elegant technical solutions' and fail to see what's staring me in the face. Option 2 does the job nicely.
Thanks
Matt
04-13-2010 09:04 AM
Disclaimer: The solutions posted by MikeS81 are the preferred method to parse out file paths.
But I love a regular expression challenge.
Try
[^\\]+\.llb
Omar
04-13-2010 10:37 AM
Thanks Omar, that'll work nicely too.
I've never really played with regular expressions before, but they do look like a really poewrful tool, which is why I was trying them out here. Got stuck by my lack of knowledge. You wouldn't happen to know of a decent tutorial / book that covers how to build these ?
Matt