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 5 1534
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
"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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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
...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
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...
| |