![]() |
RegExp to Parase File paths
Please help me identify the proper pattern to parse a path such that i
capture all the defined directories and file title. I would like to avoid the slashes and the dot from being recorded. Per se I have the path: c:\data\pictures\instru.bmp I would like the RegExp to return 4 items: c:,data,pictures,instru. As a starting point I tried:(?:[\\])(^[\\]) This returns nothing. Can you please help me fix this? Also, please advise how do I work the period into the pattern? Thank you very much for your help. |
RegExp to Parase File paths
I figured it out. The required pattern is [^\\\.]*
"bv003" wrote: Please help me identify the proper pattern to parse a path such that i capture all the defined directories and file title. I would like to avoid the slashes and the dot from being recorded. Per se I have the path: c:\data\pictures\instru.bmp I would like the RegExp to return 4 items: c:,data,pictures,instru. As a starting point I tried:(?:[\\])(^[\\]) This returns nothing. Can you please help me fix this? Also, please advise how do I work the period into the pattern? Thank you very much for your help. |
RegExp to Parase File paths
Just to mention an alternative approach:
Sub Demo() Dim s As String Dim v As Variant s = "c:\data\pictures\instru.bmp" v = Split(s, "\") End Sub Once split, you may want to adjust the file name also. -- HTH :) Dana DeLouis Windows XP & Office 2003 "bv003" wrote in message ... I figured it out. The required pattern is [^\\\.]* "bv003" wrote: Please help me identify the proper pattern to parse a path such that i capture all the defined directories and file title. I would like to avoid the slashes and the dot from being recorded. Per se I have the path: c:\data\pictures\instru.bmp I would like the RegExp to return 4 items: c:,data,pictures,instru. As a starting point I tried:(?:[\\])(^[\\]) This returns nothing. Can you please help me fix this? Also, please advise how do I work the period into the pattern? Thank you very much for your help. |
RegExp to Parase File paths
Personally, I like using the Split function for this (I haven't played
with Regular Expressions much ;-) For example, ... sPath = "c:\data\pictures\instru.bmp" aPath = split(sPath, "\") wsh.echo join(aPath, ", ") The array will then have the four pieces as the elements of the array. Tom Lavedas ============ http://members.cox.net/tglbatch/wsh bv003 wrote: Please help me identify the proper pattern to parse a path such that i capture all the defined directories and file title. I would like to avoid the slashes and the dot from being recorded. Per se I have the path: c:\data\pictures\instru.bmp I would like the RegExp to return 4 items: c:,data,pictures,instru. As a starting point I tried:(?:[\\])(^[\\]) This returns nothing. Can you please help me fix this? Also, please advise how do I work the period into the pattern? Thank you very much for your help. |
RegExp to Parase File paths
On Tue, 31 Oct 2006 13:22:02 -0800, bv003
wrote: I figured it out. The required pattern is [^\\\.]* I think you probably want: [^\\.]+ Within a character class, you don't need to escape the dot Also, with the * qualifier, you'll be matching some zero length strings -- probably not what you want. Finally, you indicated that you did NOT want to return the final suffix. So this might work IF the file name ends at the end of a line: [^\\.]+(?![^\\.]*$) --ron |
RegExp to Parase File paths
In message . com, Tue,
31 Oct 2006 14:05:28, Tom Lavedas writes Personally, I like using the Split function for this (I haven't played with Regular Expressions much Then you should. It is impossible to advise correctly and justifiably on the proper coding of string manipulations without an adequate understanding of the use of RegExps (assuming that they exist in the language in question and that a known non-trivial subset is correctly implemented). And, if you are an active coder of such things on your own behalf, and are not reasonably acquainted with RegExps, the time wasted will include your own. But in this case, if VBS RE's match Javascript ones, the OP may consider and translate F.X0.value.split(".")[0].split("\\") which gives the right result for the OP's string in control F.X0. It's a good idea to read the newsgroup and its FAQ. See below. -- (c) John Stockton, Surrey, UK. Turnpike v6.05 IE 6 <URL:http://www.jibbering.com/faq/? JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-valid.htm jscr RegExps & Validation. <URL:http://www.merlyn.demon.co.uk/ TP/BP/Delphi/jscr/&c, FAQ items, links. |
All times are GMT +1. The time now is 06:26 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com