473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

--
William Stacey [MVP]

<ja*******@gmx. de> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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.d e 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
4179
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 regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
3
11877
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 have <!]> in them. I would like to use XSLT to remove the <message> elements whose CDATA (the "...") matches a particular regular expression.
1
287
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 formula itself can contain other formula expressions like "Calc(...)", "Assign(...)" etc
4
3228
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 over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
3
1412
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 ... other lines of code ...
3
6032
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. \\server\my doc.doc is there a regular expression to do this? TIA,
7
3829
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
4
1333
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
6189
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 long set of special symbols and impossible to improve such expression. We have to create ’smart’ regular expression. Instead of write one line expression we prepare multi line text from which we shall generate our long expression. Here is a simple...
0
9534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.