Practical Parsing Using Groups in Regular Expressions

My blog has moved.
You can view this post at the following address:
http://www.osherove.com/blog/2003/5/12/practical-parsing-using-groups-in-regular-expressions.html
Published Monday, May 12, 2003 11:40 PM by RoyOsherove
Filed under:

Comments

Monday, May 12, 2003 7:40 PM by TrackBack

# ISerializable

ISerializable
Monday, May 12, 2003 7:40 PM by TrackBack

# ISerializable

ISerializable
Wednesday, May 14, 2003 5:28 AM by Anonymous

# re: Practical Parsing Using Groups in Regular Expressions

This won't work.

First, anyone viewing this on the web can't see your named groups, because they're enclosed in less-than and greater-than signs. All people see is the question-mark if they're looking at it in a browser. You need to use the ampersand-representations, < and > .

Secondly, you say the group name is case-sensitive, but in your expression you use "DAY" and in your group index you use "Day". If they are indeed case-sensitive, this example won't work.
Wednesday, May 14, 2003 8:32 AM by Royo

# re: Practical Parsing Using Groups in Regular Expressions

Thanks for the comment! I fixed it (Doh,How did I not notice??)
Hopefully it makes more sense now :)
Sorry if this confused anyone...
Wednesday, May 28, 2003 6:34 PM by Shawn A. Van Ness

# How to enumerate the named capturing groups in a regex?

Hi Roy,

First off, if you were using the regex-based C# colorizer that Wes H and I have been working on, that anglebracket bug was my fault. Sorry! ;)

But that's not why I'm writing... or actually yes, it is. I was trying to add a feature to that same product, one which would ultimately require "reflecting" on a user-entered regex to get a list of named capturing groups.

Short of scanning a regex pattern with a regex (ugh!) I can't seem to find a way to do that.

IOW, it looks like although GroupCollection allows us to index by string, it doesn not allow us to enumerate by string.

You may have more experience than me, in this area -- am I missing something?

Wednesday, May 28, 2003 6:59 PM by Royo

# re: Practical Parsing Using Groups in Regular Expressions

Hey Shawn.
Actually, I Copy-Pasting from VS.NET into the editor.
Second, As for your question, It seems a pretty complicated case, and off the top of my head, I can't think of a better way than parsing Regex patterns with Regex patterns :)

However, If i'll come up with something , I'll let you know about it :)
I suggest, If you havn't yet, Trying to post on the Regex Mailing list from ASPAlliance.com
The folks there might help...
They have more experience than me on this subject.
Thursday, March 11, 2004 2:53 PM by Humberto Oliveira

# re: Practical Parsing Using Groups in Regular Expressions

Hi,

I really enjoyed your articles. They were very elucidative to me. I am facing a situation similiar to your article at MSDN (Turn Your Log Files into Searchable Data Using Regex and the XML Classes). Your solution seems to suit very well my needs except for the fact that the field in my log files are not separated by tabs, but they have fix lengths and space characters between them. Here is a sample:

FIRST PRES. PURCHASE ORIG 61 8 1,126.89 DR 1,126.89 DR 840-USD 21.25 CR 840-USD

I have the schema for the file and I know the exact location of the fields in the line(starting column and lenght). Can I use a regular expression to separate all the fields based on their positions? If not, do you suggest a different approach?

Thanks,

Humberto Oliveira
Tuesday, March 16, 2004 4:47 PM by mahmood khalid

# re: Practical Parsing Using Groups in Regular Expressions

i need my match.
Tuesday, June 15, 2004 7:36 PM by codevigilante

# re: Practical Parsing Using Groups in Regular Expressions

A quick question, how would one format the regular expression if the months were stored as Jan, Feb, Mar, etc. ? I have been trying to learn regular expressions and cannot figure it out.
Saturday, July 10, 2004 10:42 AM by Robert

# re: Practical Parsing Using Groups in Regular Expressions

Hello!
You use th format dd/MM/yyyy for date.
why don't use yyyy-MM-dd ?
i've seen many and many examples that use dd/MM/yyyy format.
But i think that format make confusion.
It's my personal opinion and problem?
Monday, July 12, 2004 7:49 PM by TrackBack

# Nice articles about groups in regex

Monday, January 10, 2005 5:04 PM by TrackBack

# Regular Expressions

Monday, January 10, 2005 5:05 PM by TrackBack

# Regular Expressions

Monday, January 10, 2005 5:06 PM by TrackBack

# Regular Expressions

Thursday, May 25, 2006 11:36 AM by Writing abs() function using Regular Expression

# re: Practical Parsing Using Groups in Regular Expressions

HI,
Is it possible to write abs() function in regular expression? If so pls explain. Thanks in advance.
Friday, July 14, 2006 1:22 PM by AL

# re: Practical Parsing Using Groups in Regular Expressions

I was wondering how to use regular expressions to parse columns of a line?