473,406 Members | 2,259 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,406 software developers and data experts.

Simple regex question - match parameter in URL

Sorry to ask something so elementary, but I'm just not getting it.

suppose I want to match the value of parameter b from a URL like
http://www.abcd.com/?a=1&b=2&c=3

I can use this regex expression:
&b=(.+)&

and then pull the value of group 1.

But suppose the c parameter is not included - the URL is
http://www.abcd.com/?a=1&b=2

Then, of course, the & doesn't match. So I have to replace it with
either nothing, or \b, or \Z, or something equivalent. They all work.

What I *don't* get is how to OR those conditions together. If the
second condition were a character, then I could create a character
class. But even though "&b=(.+)\Z" works, "&b=(.+)[\Z]" does not.

I know there's something simple here I'm not quite getting. Can some
provide a clue? Thanks.

Apr 3 '07 #1
2 8585
I am pretty sure that
&b=(.+)&?
will work.
The question mark means zero or one match

Ethan
"Warren" <ws*****@wsdesigns.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Sorry to ask something so elementary, but I'm just not getting it.

suppose I want to match the value of parameter b from a URL like
http://www.abcd.com/?a=1&b=2&c=3

I can use this regex expression:
&b=(.+)&

and then pull the value of group 1.

But suppose the c parameter is not included - the URL is
http://www.abcd.com/?a=1&b=2

Then, of course, the & doesn't match. So I have to replace it with
either nothing, or \b, or \Z, or something equivalent. They all work.

What I *don't* get is how to OR those conditions together. If the
second condition were a character, then I could create a character
class. But even though "&b=(.+)\Z" works, "&b=(.+)[\Z]" does not.

I know there's something simple here I'm not quite getting. Can some
provide a clue? Thanks.

Apr 3 '07 #2
The following will capture ALL parameters in a QueryString, placing the name
into a group named "name" and the value into a group named "value":

[\?&](?<name>[^&=]+)=(?<value>[^&=]+)

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Warren" <ws*****@wsdesigns.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Sorry to ask something so elementary, but I'm just not getting it.

suppose I want to match the value of parameter b from a URL like
http://www.abcd.com/?a=1&b=2&c=3

I can use this regex expression:
&b=(.+)&

and then pull the value of group 1.

But suppose the c parameter is not included - the URL is
http://www.abcd.com/?a=1&b=2

Then, of course, the & doesn't match. So I have to replace it with
either nothing, or \b, or \Z, or something equivalent. They all work.

What I *don't* get is how to OR those conditions together. If the
second condition were a character, then I could create a character
class. But even though "&b=(.+)\Z" works, "&b=(.+)[\Z]" does not.

I know there's something simple here I'm not quite getting. Can some
provide a clue? Thanks.

Apr 3 '07 #3

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

Similar topics

5
by: Bill Cohagan | last post by:
I'm looking for help with a regular expression question, so my first question is which newsgroup is the best one to post to? Just in case *this* is the best choice, here's the problem: I'm...
3
by: Vidar Skjelanger | last post by:
I have a regex for matching VB6-functions, but it hangs on one specific function. The regex: ...
7
by: Razzie | last post by:
Hey all, Decided to give a shot at Regular expressions - need a bit of help :) I can't seem to find the right regex for matching words like "*test*" or *somevalue*" - in short, all words...
3
by: Michael D Murphy | last post by:
Hi, I would like to know how to use Regular Expressions to iteratively return and print the items between the colons in the following string to say the console.. Any help would be appreciated....
6
by: Jake Barnes | last post by:
This function has always worked for me just fine: function nl2br_js(myString){ // 02-18-06 - this function imitates the PHP command nl2br, which finds newlines in a string // and replaces them...
2
by: Thomas T. Veldhouse | last post by:
Hello. I have been working with a client of mine on their seriazation code and we seem to have run into an issue when we migrated from .NET 1.1 to .NET 2.0. We have a framework of business...
3
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
1
by: DougJrs | last post by:
Good Morning, I am trying to write a simple function that would grab the "errorId" parameter and then display a message when the page loads. I basically have a login page (login.asp) that if...
7
by: VUNETdotUS | last post by:
How can I get the text after matching string is found: var str = "1111>AAAA<2222>BBBB<3333>CCCC"; if(str.indexOf("2222>")){ //how to get "BBBB" value following my "2222>" but before "<3333"...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
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
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.