extract UNC path using regular expression

K

ksr

Hi,
I am looking for a regular expression that would extract UNC paths from a
given string and place that inside a href.
Currently the expression fails if there is a space in the path..

eg. \\server\my doc.doc

is there a regular expression to do this?

TIA,
ks
 
J

Jouni Heikniemi

I am looking for a regular expression that would extract UNC paths from a
given string and place that inside a href.
Currently the expression fails if there is a space in the path..
eg. \\server\my doc.doc
is there a regular expression to do this?

Regexps are not magic. If you have a string like "Jake, read the docs in
\\server1\code documentation\coolproject for windows and its
subdirectories", it's impossible to make a reasonable guess on where the
UNC path might end.

So, if you can come up with the logic first, then you can ask for a regexp
representation.
 
K

ksr

Thnaks for the reply. This is what the requirement is.. There is a multiline
textbox and users can enter some text and UNC path. If there is space
between the words inside path then the path will be enclosed in <path goes
here> . I am new to regular expressions and looking for some help in this
regard.

Hope this clears the logic part of it. Please help me with this

Appreciate your help

TIA
 
J

Jouni Heikniemi

in <path goes here> . I am new to regular expressions and looking for
some help in this regard.
Hope this clears the logic part of it. Please help me with this

Read a tutorial, it'll help you in the future.
<http://www.regular-expressions.info> is a decent one.

Try this for a regexp: (?:<(\\\\[-\d\w\\\s]+?)>)|(\\\\[-\d\w\\]+)

It should capture the UNCs you want. Note that if you put it into a C#
string, you need to double all backspaces (yes, there are quite a few of
them then).
 
Joined
Sep 21, 2009
Messages
2
Reaction score
0
New URL for channel9 post

The URL mfreidge posted didn't work for me so I searched the site and found this thread. Not sure if it's the same one but I found it useful.

channel9.msdn.com/forums/TechOff/132283-regex-UNC-share

(My post count isn't high enough to post URLs -- you'll have to copy & paste this URL to your browser Address control.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top