regular expression to extract elements from url

  • Thread starter Thread starter jarod1701
  • Start date Start date
J

jarod1701

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:[email protected]

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
 
Does the Uri or UriBuilder classes not work for your needs?
 
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
 

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

Similar Threads


Back
Top