473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

regular expression to extract elements from url

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
3 5025
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
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
thanks to both of you :-)

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Edwin G. Castro | last post by:
Hi, I'm new to XSLT and I'm having a hard time figuring out whether XSLT will do what I need it to do. I have a XML file with a whole bunch of <message> elements. These <message> elements...
1
by: Picho | last post by:
Hi all, first of all, does anyone know of a newsgroup dedicated for regular expressions? second - my problem: I have a string that represents a formula of the format: "formula(...)" the...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: Gianluca | last post by:
Hi, I'm using regular expressions to extract some information from my vb.net source code files. I have something like this: 1: '<class name="xyz" description="xxxxxx"/> 2: Class xyz ......
3
by: ksr | last post by:
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....
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
4
by: duikboot | last post by:
Hello, I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. Could you please help me? I expected:
0
by: altavim | last post by:
Usually when you make regular expression to extract text you are starting from simple expression. When you got to know target text, you are extending your expression. Subsequently very hard to ready...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.