Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 2
Default 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.
  #2   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 2
Default 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.

  #3   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 947
Default 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.



  #4   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 7
Default 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.


  #5   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 5,651
Default 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


  #6   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming,microsoft.public.office.developer.automation
external usenet poster
 
Posts: 1
Default 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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External File Paths Stuart[_3_] Excel Programming 6 September 18th 06 06:10 PM
excel file paths Jane Excel Discussion (Misc queries) 1 August 17th 06 04:59 PM
Using Variables for file paths in QueryTables.Add Zik Excel Programming 0 July 25th 06 03:42 PM
How do I do a vlookup that links to file paths within a cell ref Foozy Excel Worksheet Functions 2 July 13th 06 11:32 AM
file paths hr Excel Discussion (Misc queries) 0 December 7th 05 04:59 PM


All times are GMT +1. The time now is 02:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"