By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,248 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,248 IT Pros & Developers. It's quick & easy.

regular expression to extract elements from url

P: n/a
Hi,

I'm currently trying to create a regular expression that can extract
certain elements from a url.

The url will be of the following form:
http://user:pa**@www.sitename.com

I want a regex that matches the "user" part of that url.

My first approach was ([:][/][/]([a-z]*)[:]) but that only return
"://user:".

I would have to use .NET's substring method to extract the "user" but I
don't want to do that.
I've been searching through the web for quite a while now
Isn't there a way to get the substring from "://user:" using something
like a subpattern ?

Is it possible after all ?

Thanks in advance

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Does the Uri or UriBuilder classes not work for your needs?

--
William Stacey [MVP]

<ja*******@gmx.de> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

I'm currently trying to create a regular expression that can extract
certain elements from a url.

The url will be of the following form:
http://user:pa**@www.sitename.com

I want a regex that matches the "user" part of that url.

My first approach was ([:][/][/]([a-z]*)[:]) but that only return
"://user:".

I would have to use .NET's substring method to extract the "user" but I
don't want to do that.
I've been searching through the web for quite a while now
Isn't there a way to get the substring from "://user:" using something
like a subpattern ?

Is it possible after all ?

Thanks in advance

Nov 17 '05 #2

P: n/a
What do you exactly want to extract? You can extract the elements to
some group.

Try the following.

(http://)(?<User>.*):(?<Password>.*)@.*

it will extract the user into the <User> group, and pass into <Password>
group.

HTH.

Jianwei

ja*******@gmx.de wrote:
Hi,

I'm currently trying to create a regular expression that can extract
certain elements from a url.

The url will be of the following form:
http://user:pa**@www.sitename.com

I want a regex that matches the "user" part of that url.

My first approach was ([:][/][/]([a-z]*)[:]) but that only return
"://user:".

I would have to use .NET's substring method to extract the "user" but I
don't want to do that.
I've been searching through the web for quite a while now
Isn't there a way to get the substring from "://user:" using something
like a subpattern ?

Is it possible after all ?

Thanks in advance

Nov 17 '05 #3

P: n/a
thanks to both of you :-)

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.