473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex help?

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 trying to "parse" something that looks like a command line; e.g.,

op arg1, arg2, ..., argn

The individual parts (op, arg1, ...) can be matched with a \w+ pattern --
except that the args *might* be quoted to cover the case where they contain
non \w characters. I've figured out what I think is the "right" pattern, but
what I'm unsure of is how to interpret the results.

What I'm trying to accomplish is to perform a Match operation, then walk
through the resulting match groups and their respective captures, producing
an array containing the arguments. The problem I have is determining the
*order* of things in the captures. Here's the detail...

The pattern for matching the args is an alternation: ((\w+)|"([^"]*)"). This
pattern of course occurs within a repeating outer group so for *this* group
there will be a capture collection with multiple elements. The problem of
course is that the captures will include the quote chars for those cases
where the right alternative was matched. What I want is just what's inside
the quotes. The inner groups (\w+) and ([^"]*) of course have their own
capture collections and these contain exactly what I want, but I don't see
how to determine the order.

To see the problem consider the case: op a, "b", c. The capture group for
the group containing the alternation will contain a, "b", c while the
capture group for the left subgroup will contain a, c and the right subgroup
will contain b. How can I tell the relative order so I can "merge" these
into a, b, c which is the desired result?

Of course I can just use the outer group and reparse the elements of the
capture collection, stripping out the quote chars where necessary, but I'd
like to know how this could be done just using regular expressions. Is it
possible?

Thanks in advance.

Bill
Jul 21 '05 #1
5 1534
Bill,

I hate Regex, therefore here two links

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor
Jul 21 '05 #2
Cor
Thanks for the response. These look like pretty good sites for finding
patterns, but unfortunately that's not my problem -- at least I don't think
so. What I need is some help in interpreting the results and in a .Net
specific way since I believe that capture collections are unique to .Net
regex.

Regards,
Bill

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Bill,

I hate Regex, therefore here two links

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor

Jul 21 '05 #3
"Bill Cohagan" <co*****@teraXNOSPAMXquest.com> wrote in
news:eT*************@TK2MSFTNGP12.phx.gbl...
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 trying to "parse" something that looks like a command line; e.g.,

op arg1, arg2, ..., argn

The individual parts (op, arg1, ...) can be matched with a \w+ pattern --
except that the args *might* be quoted to cover the case where they
contain
non \w characters. I've figured out what I think is the "right" pattern,
but
what I'm unsure of is how to interpret the results.

What I'm trying to accomplish is to perform a Match operation, then walk
through the resulting match groups and their respective captures,
producing
an array containing the arguments. The problem I have is determining the
*order* of things in the captures. Here's the detail...

The pattern for matching the args is an alternation: ((\w+)|"([^"]*)").
This
pattern of course occurs within a repeating outer group so for *this*
group
there will be a capture collection with multiple elements. The problem of
course is that the captures will include the quote chars for those cases
where the right alternative was matched. What I want is just what's inside
the quotes. The inner groups (\w+) and ([^"]*) of course have their own
capture collections and these contain exactly what I want, but I don't see
how to determine the order.

To see the problem consider the case: op a, "b", c. The capture group for
the group containing the alternation will contain a, "b", c while the
capture group for the left subgroup will contain a, c and the right
subgroup
will contain b. How can I tell the relative order so I can "merge" these
into a, b, c which is the desired result?

Of course I can just use the outer group and reparse the elements of the
capture collection, stripping out the quote chars where necessary, but I'd
like to know how this could be done just using regular expressions. Is it
possible?


You could use the "Index" property of the capture objects to get the
captures into order, but I'm not sure if that's the kind of "elegant"
solution you're looking for.

Can't you use the "Matches" method, and let it return one Match item per
"parameter"? That would certainly make things easier. I guess the problem
here is the "op" part; Maybe you could strip that away first: Use one regex
that splits your string into "operation" and "parameter list", and a second
one to split the parameters. (I think that's the "standard regex way", as
many regex engines don't track capture objects)

Hope this helps,

Niki
Jul 21 '05 #4
Niki
I hadn't thought of looking at the Index property -- that might be what I
need. As for the Matches method I don't think it'd solve the problem since I
have groups whose matches would be included in the collection, but whose
values I don't want to see. (Actually it might be possible to use "non
capturing" groups in conjunction with Matches to do something ...)

Thanks for the suggestions. I'll post back with what I find.

Bill

"Niki Estner" <ni*********@cube.net> wrote in message
news:OQ**************@TK2MSFTNGP15.phx.gbl...
"Bill Cohagan" <co*****@teraXNOSPAMXquest.com> wrote in
news:eT*************@TK2MSFTNGP12.phx.gbl...
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 trying to "parse" something that looks like a command line; e.g.,

op arg1, arg2, ..., argn

The individual parts (op, arg1, ...) can be matched with a \w+ pattern -- except that the args *might* be quoted to cover the case where they
contain
non \w characters. I've figured out what I think is the "right" pattern,
but
what I'm unsure of is how to interpret the results.

What I'm trying to accomplish is to perform a Match operation, then walk
through the resulting match groups and their respective captures,
producing
an array containing the arguments. The problem I have is determining the
*order* of things in the captures. Here's the detail...

The pattern for matching the args is an alternation: ((\w+)|"([^"]*)").
This
pattern of course occurs within a repeating outer group so for *this*
group
there will be a capture collection with multiple elements. The problem of course is that the captures will include the quote chars for those cases
where the right alternative was matched. What I want is just what's inside the quotes. The inner groups (\w+) and ([^"]*) of course have their own
capture collections and these contain exactly what I want, but I don't see how to determine the order.

To see the problem consider the case: op a, "b", c. The capture group for the group containing the alternation will contain a, "b", c while the
capture group for the left subgroup will contain a, c and the right
subgroup
will contain b. How can I tell the relative order so I can "merge" these
into a, b, c which is the desired result?

Of course I can just use the outer group and reparse the elements of the
capture collection, stripping out the quote chars where necessary, but I'd like to know how this could be done just using regular expressions. Is it possible?
You could use the "Index" property of the capture objects to get the
captures into order, but I'm not sure if that's the kind of "elegant"
solution you're looking for.

Can't you use the "Matches" method, and let it return one Match item per
"parameter"? That would certainly make things easier. I guess the problem
here is the "op" part; Maybe you could strip that away first: Use one

regex that splits your string into "operation" and "parameter list", and a second one to split the parameters. (I think that's the "standard regex way", as
many regex engines don't track capture objects)

Hope this helps,

Niki

Jul 21 '05 #5
Niki

Thanks again for the suggestions. I was able to accomplish the goal using
the Index property as the key in a merge of the two capture groups. Works
like a charm.

I'd hoped to do this all with regular expressions, but at least the code I
had to write was fun. I finally got to use a Queue!

Bill

"Niki Estner" <ni*********@cube.net> wrote in message
news:OQ**************@TK2MSFTNGP15.phx.gbl...
"Bill Cohagan" <co*****@teraXNOSPAMXquest.com> wrote in
news:eT*************@TK2MSFTNGP12.phx.gbl...
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 trying to "parse" something that looks like a command line; e.g.,

op arg1, arg2, ..., argn

The individual parts (op, arg1, ...) can be matched with a \w+ pattern -- except that the args *might* be quoted to cover the case where they
contain
non \w characters. I've figured out what I think is the "right" pattern,
but
what I'm unsure of is how to interpret the results.

What I'm trying to accomplish is to perform a Match operation, then walk
through the resulting match groups and their respective captures,
producing
an array containing the arguments. The problem I have is determining the
*order* of things in the captures. Here's the detail...

The pattern for matching the args is an alternation: ((\w+)|"([^"]*)").
This
pattern of course occurs within a repeating outer group so for *this*
group
there will be a capture collection with multiple elements. The problem of course is that the captures will include the quote chars for those cases
where the right alternative was matched. What I want is just what's inside the quotes. The inner groups (\w+) and ([^"]*) of course have their own
capture collections and these contain exactly what I want, but I don't see how to determine the order.

To see the problem consider the case: op a, "b", c. The capture group for the group containing the alternation will contain a, "b", c while the
capture group for the left subgroup will contain a, c and the right
subgroup
will contain b. How can I tell the relative order so I can "merge" these
into a, b, c which is the desired result?

Of course I can just use the outer group and reparse the elements of the
capture collection, stripping out the quote chars where necessary, but I'd like to know how this could be done just using regular expressions. Is it possible?
You could use the "Index" property of the capture objects to get the
captures into order, but I'm not sure if that's the kind of "elegant"
solution you're looking for.

Can't you use the "Matches" method, and let it return one Match item per
"parameter"? That would certainly make things easier. I guess the problem
here is the "op" part; Maybe you could strip that away first: Use one

regex that splits your string into "operation" and "parameter list", and a second one to split the parameters. (I think that's the "standard regex way", as
many regex engines don't track capture objects)

Hope this helps,

Niki

Jul 21 '05 #6

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

Similar topics

6
4775
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
8024
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
2219
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
2071
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
2621
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
2565
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
4190
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
12133
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
1614
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
7223
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
7115
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
7377
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
7489
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...
1
5047
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...
0
4705
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
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 ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.