473,378 Members | 1,421 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,378 software developers and data experts.

RegEx needed to parse a URL

I'm building a test platform that includes parsing a set of URL's. This is
not part of a ASP.Net project. Otherwise I'd be posting it in that area.

Given a URL of
http://Somthing/Somthing.asp?parm1=v...al2&parm3=val3

I'm trying to create an expression that gives me:
parm1=val1
parm2=val2
parm3=val3

As either distinct group values (Match (str).Groups) or as captures of a
group (Match (str).Groups[1].Captures)

I've tried @".*\?(.*&)*?(.*)"
but this gives me the first two parms as a single string with the last parm
being distinct. I've also tried other variations but this is the closest I've
gotten.

TIA,
Dave
Jun 13 '06 #1
4 1512
Why not just strip before ? and split it on the &. That will give you an
array containing what your after.
--
Regards

John Timney (MVP)
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
I'm building a test platform that includes parsing a set of URL's. This is
not part of a ASP.Net project. Otherwise I'd be posting it in that area.

Given a URL of
http://Somthing/Somthing.asp?parm1=v...al2&parm3=val3

I'm trying to create an expression that gives me:
parm1=val1
parm2=val2
parm3=val3

As either distinct group values (Match (str).Groups) or as captures of a
group (Match (str).Groups[1].Captures)

I've tried @".*\?(.*&)*?(.*)"
but this gives me the first two parms as a single string with the last
parm
being distinct. I've also tried other variations but this is the closest
I've
gotten.

TIA,
Dave

Jun 13 '06 #2
While I realise its not RegEx (they make my head ache), something like this
might work:
Uri uri = new
Uri(@http://Somthing/Somthing.asp?parm1=val1&parm2=val2&parm3=val3);
string[] querystrings = uri.Query.Replace("?", "").Split('&');
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
I'm building a test platform that includes parsing a set of URL's. This is
not part of a ASP.Net project. Otherwise I'd be posting it in that area.

Given a URL of
http://Somthing/Somthing.asp?parm1=v...al2&parm3=val3

I'm trying to create an expression that gives me:
parm1=val1
parm2=val2
parm3=val3

As either distinct group values (Match (str).Groups) or as captures of a
group (Match (str).Groups[1].Captures)

I've tried @".*\?(.*&)*?(.*)"
but this gives me the first two parms as a single string with the last
parm
being distinct. I've also tried other variations but this is the closest
I've
gotten.

TIA,
Dave

Jun 13 '06 #3
(?<=[^?\s\n]+\?)([^\s\n]+)

This uses a positive look-behind to ensure that a match (any text that has
no spaces or line breaks in it) is preceded by a URL (any text that does not
contain a line break, space, or question mark), followed by a question mark.
This effectively divides the matches by URL. So, each match will be a single
Query String.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
I'm building a test platform that includes parsing a set of URL's. This is
not part of a ASP.Net project. Otherwise I'd be posting it in that area.

Given a URL of
http://Somthing/Somthing.asp?parm1=v...al2&parm3=val3

I'm trying to create an expression that gives me:
parm1=val1
parm2=val2
parm3=val3

As either distinct group values (Match (str).Groups) or as captures of a
group (Match (str).Groups[1].Captures)

I've tried @".*\?(.*&)*?(.*)"
but this gives me the first two parms as a single string with the last
parm
being distinct. I've also tried other variations but this is the closest
I've
gotten.

TIA,
Dave

Jun 13 '06 #4
I'm so used to parsing with regular expressions I forget about normal string
manipulation. :o

Thanks

"Stuart Irving" wrote:
While I realise its not RegEx (they make my head ache), something like this
might work:
Uri uri = new
Uri(@http://Somthing/Somthing.asp?parm1=val1&parm2=val2&parm3=val3);
string[] querystrings = uri.Query.Replace("?", "").Split('&');
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
I'm building a test platform that includes parsing a set of URL's. This is
not part of a ASP.Net project. Otherwise I'd be posting it in that area.

Given a URL of
http://Somthing/Somthing.asp?parm1=v...al2&parm3=val3

I'm trying to create an expression that gives me:
parm1=val1
parm2=val2
parm3=val3

As either distinct group values (Match (str).Groups) or as captures of a
group (Match (str).Groups[1].Captures)

I've tried @".*\?(.*&)*?(.*)"
but this gives me the first two parms as a single string with the last
parm
being distinct. I've also tried other variations but this is the closest
I've
gotten.

TIA,
Dave


Jun 13 '06 #5

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

Similar topics

8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
4
by: JS | last post by:
I am writing a C# app that needs to parse a sentence entered by the user for a simple boolean search. I need to capture all of the AND words that are not inside of double quotes. However, I am...
13
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
8
by: rh0dium | last post by:
Hi all, I am using python to drive another tool using pexpect. The values which I get back I would like to automatically put into a list if there is more than one return value. They provide me...
1
by: Terry Olsen | last post by:
I download xml logs from several servers every day and read the data out of them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
7
by: MrNobody | last post by:
I'm trying to do some regex in C# but for some reason linebreaks are causing my regex to not work. the test string goes like this: string ss = "<tagname...
5
by: Bragadiru | last post by:
Hi, I'm using the following Regex to parse for method parameters. It works if there are no spaces between commas. How can I change the regex to support method calls like : MyMethod('uno', ...
1
by: billy.murray | last post by:
I have the following text inside a file which I am trying to parse. I am creating a new RegEx object as follows :- string strRegex = @"({S:\r?\n)(*)(})" {S: INTERLOCK FAIL : Tie bar...
4
by: CJ | last post by:
Is this the format to parse a string and return the value between the item? Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>"); I am trying to parse this string. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.