LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use regular expressions to extract .llb filename from path

Solved!
Go to solution

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

 

 

 

 

 

0 Kudos
Message 1 of 5
(3,796 Views)
Solution
Accepted by topic author Zedd

Hi Matt,

attached you'll find two other options.

 

Mike

Message Edited by MikeS81 on 04-13-2010 01:30 PM
0 Kudos
Message 2 of 5
(3,790 Views)

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

0 Kudos
Message 3 of 5
(3,769 Views)

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

Omar
Message 4 of 5
(3,753 Views)

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

0 Kudos
Message 5 of 5
(3,740 Views)