473,788 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expressions Named Groups Problem

Hey,

I have only been playing with regular expressions for some time. I am
working on some code that parses and object 560 event log. I have created
two expressions the first one which works okay is for the actual csv of each
log. The second one parses out the description of the log. My problem is
with the accesses section of the description.

How do I parse multiple groups that have the same name. When I do a for
each through the groups I get the first value for each.

Snippet:
-----------------------------------------------
expression:
Accesses:\t(?:( ?<accesses>.+)\ s+)+?^(?: \t)

log section:
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes

Privileges: -

I would like to do something like

Match m = Regex.Match(log , expression);
foreach(string access in m.Groups["accesses"])
{
//write that access
}
Is this possible?

PS. I am using "The Regulator" for testing and it is successfully parsing
the Accesses in to groups.

Also, I have tried:
Match m = Regex.Match(log , expression);
foreach(string access in m.Groups)
{
// write access
}

it successfully matches 5 groups but the all equal to READ_CONTROL
Nov 16 '05 #1
4 2183
Wes
Hello Ben,

try:
foreach(Match m in Regex.Matches(l og, expression)
{
string access = m.Groups["accesses"].Value;
//write that access
}

Note: I have compiled or tested this it is from the top of my head.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hey,

I have only been playing with regular expressions for some time. I am
working on some code that parses and object 560 event log. I have
created two expressions the first one which works okay is for the
actual csv of each log. The second one parses out the description of
the log. My problem is with the accesses section of the description.

How do I parse multiple groups that have the same name. When I do a
for each through the groups I get the first value for each.

Snippet:
-----------------------------------------------
expression:
Accesses:\t(?:( ?<accesses>.+)\ s+)+?^(?: \t)
log section:
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes
Privileges: -

I would like to do something like

Match m = Regex.Match(log , expression);
foreach(string access in m.Groups["accesses"])
{
//write that access
}
Is this possible?

PS. I am using "The Regulator" for testing and it is successfully
parsing the Accesses in to groups.

Also, I have tried:
Match m = Regex.Match(log , expression);
foreach(string access in m.Groups)
{
// write access
}
it successfully matches 5 groups but the all equal to READ_CONTROL


Nov 16 '05 #2
the problem with that is that is won't work for the entire log
description...

Object Open:
Object Server: Security
Object Type: File
Object Name: D:\folder1\fold er2\line-end.gif
Handle ID: 1504
Operation ID: {0,573337772}
Process ID: 9532
Image File Name: C:\WINDOWS\syst em32\inetsrv\w3 wp.exe
Primary User Name: NETWORK SERVICE
Primary Domain: NT AUTHORITY
Primary Logon ID: (0x0,0x3E4)
Client User Name: user1
Client Domain: DOMAIN1
Client Logon ID: (0x0,0x222C6B1A )
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes

Privileges: -
Restricted Sid Count: 0
Access Mask: 0x120089

This entire expression is suppose to return all the values plus an array of
values for Accesses.

[\w ]+:\s+Object\ Server:\t(?<ser ver>\w+)\s+Obje ct\
Type:\t(?<type> \w+)\s+Object\ Name:\t(?<name> .[^\r\n]+)\s+Handle\
ID:\t(?<handleI d>\d+)\s+Operat ion\ ID:\t(?<operati onId>[\d{},]+)\s+Process\
ID:\t(?<process Id>\d+)\s+Image \ File\
Name:\t(?<image FileName>\w+)?\ s+Primary\ User\
Name:\t(?<prima ryUserName>.[^\r\n]+)\s+Primary\
Domain:\t(?<pri maryDomain>\w+) \s+Primary\ Logon\
ID:\t(?<primary LogonID>[\d(),A-Fa-fx]+)\s+Client\ User\
Name:\t(?<clien tUserName>[\w _-]+)\s+Client\ Domain:\t(?<cli entDomain>[\w
_-]+)\s+Client\ Logon\
ID:\t(?<clientL ogonId>[\d(),A-Fa-fx]+)\s+Accesses:\ t(?:(?<accesses >.+)\s+)+?^(? :
\t)\s+Privilege s:\t(?<privileg es>[\w -_]+)\s+Restricted \ Sid\
Count:\t(?<rest rictedSidCount> \d+)\s+Access\ Mask:\t(?<acces sMask>[\dx]+)

"Wes" <ne********@NOS PAMpuzzleware.n et> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello Ben,

try:
foreach(Match m in Regex.Matches(l og, expression)
{
string access = m.Groups["accesses"].Value;
//write that access
}

Note: I have compiled or tested this it is from the top of my head.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hey,

I have only been playing with regular expressions for some time. I am
working on some code that parses and object 560 event log. I have
created two expressions the first one which works okay is for the
actual csv of each log. The second one parses out the description of
the log. My problem is with the accesses section of the description.

How do I parse multiple groups that have the same name. When I do a
for each through the groups I get the first value for each.

Snippet:
-----------------------------------------------
expression:
Accesses:\t(?:( ?<accesses>.+)\ s+)+?^(?: \t)
log section:
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes
Privileges: -

I would like to do something like

Match m = Regex.Match(log , expression);
foreach(string access in m.Groups["accesses"])
{
//write that access
}
Is this possible?

PS. I am using "The Regulator" for testing and it is successfully
parsing the Accesses in to groups.

Also, I have tried:
Match m = Regex.Match(log , expression);
foreach(string access in m.Groups)
{
// write access
}
it successfully matches 5 groups but the all equal to READ_CONTROL

Nov 16 '05 #3
For anyone trying to parse the event log for an object of type 560 here is
the entire expression. I am using this expression to parse an event log
entry in order to track a users access to files and folders. The expression
works, I am still trying figure out the best way to get the values using
..NET (ie. get the array for the accesses section)
log
(?<date>[\d/]+),(?<time>[\d:
APM]+),(?<type>\w+) ,(?<auditType>[\w ]+),(?<accessTyp e>[\w ]+),(?<eventId>\ d+),(?<user>[\w
\\]+),(?<machine>[\w- ]+,"(?<descripti on>.[^"]+)"
description
[\w ]+:\s+Object\ Server:\t(?<ser ver>\w+)\s+Obje ct\
Type:\t(?<type> \w+)\s+Object\ Name:\t(?<name> .[^\r\n]+)\s+Handle\
ID:\t(?<handleI d>\d+)\s+Operat ion\ ID:\t(?<operati onId>[\d{},]+)\s+Process\
ID:\t(?<process Id>\d+)\s+Image \ File\
Name:\t(?<image FileName>\w+)?\ s+Primary\ User\
Name:\t(?<prima ryUserName>.[^\r\n]+)\s+Primary\
Domain:\t(?<pri maryDomain>\w+) \s+Primary\ Logon\
ID:\t(?<primary LogonID>[\d(),A-Fa-fx]+)\s+Client\ User\
Name:\t(?<clien tUserName>[\w _-]+)\s+Client\ Domain:\t(?<cli entDomain>[\w
_-]+)\s+Client\ Logon\
ID:\t(?<clientL ogonId>[\d(),A-Fa-fx]+)\s+Accesses:\ t(?:(?<accesses >.+)\s+)+?^(? :
\t)\s+Privilege s:\t(?<privileg es>[\w -_]+)\s+Restricted \ Sid\
Count:\t(?<rest rictedSidCount> \d+)\s+Access\ Mask:\t(?<acces sMask>[\dx]+)

"Wes" <ne********@NOS PAMpuzzleware.n et> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello Ben,

try:
foreach(Match m in Regex.Matches(l og, expression)
{
string access = m.Groups["accesses"].Value;
//write that access
}

Note: I have compiled or tested this it is from the top of my head.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hey,

I have only been playing with regular expressions for some time. I am
working on some code that parses and object 560 event log. I have
created two expressions the first one which works okay is for the
actual csv of each log. The second one parses out the description of
the log. My problem is with the accesses section of the description.

How do I parse multiple groups that have the same name. When I do a
for each through the groups I get the first value for each.

Snippet:
-----------------------------------------------
expression:
Accesses:\t(?:( ?<accesses>.+)\ s+)+?^(?: \t)
log section:
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes
Privileges: -

I would like to do something like

Match m = Regex.Match(log , expression);
foreach(string access in m.Groups["accesses"])
{
//write that access
}
Is this possible?

PS. I am using "The Regulator" for testing and it is successfully
parsing the Accesses in to groups.

Also, I have tried:
Match m = Regex.Match(log , expression);
foreach(string access in m.Groups)
{
// write access
}
it successfully matches 5 groups but the all equal to READ_CONTROL

Nov 16 '05 #4
Wes
Hello Ben,

Isn't there someway to use the EventLog class in the .Net Framework to do what you are trying to do?

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

the problem with that is that is won't work for the entire log
description...

Object Open:
Object Server: Security
Object Type: File
Object Name: D:\folder1\fold er2\line-end.gif
Handle ID: 1504
Operation ID: {0,573337772}
Process ID: 9532
Image File Name: C:\WINDOWS\syst em32\inetsrv\w3 wp.exe
Primary User Name: NETWORK SERVICE
Primary Domain: NT AUTHORITY
Primary Logon ID: (0x0,0x3E4)
Client User Name: user1
Client Domain: DOMAIN1
Client Logon ID: (0x0,0x222C6B1A )
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes
Privileges: -
Restricted Sid Count: 0
Access Mask: 0x120089
This entire expression is suppose to return all the values plus an
array of values for Accesses.

[\w ]+:\s+Object\ Server:\t(?<ser ver>\w+)\s+Obje ct\
Type:\t(?<type> \w+)\s+Object\ Name:\t(?<name> .[^\r\n]+)\s+Handle\
ID:\t(?<handleI d>\d+)\s+Operat ion\
ID:\t(?<operati onId>[\d{},]+)\s+Process\
ID:\t(?<process Id>\d+)\s+Image \ File\
Name:\t(?<image FileName>\w+)?\ s+Primary\ User\
Name:\t(?<prima ryUserName>.[^\r\n]+)\s+Primary\
Domain:\t(?<pri maryDomain>\w+) \s+Primary\ Logon\
ID:\t(?<primary LogonID>[\d(),A-Fa-fx]+)\s+Client\ User\
Name:\t(?<clien tUserName>[\w _-]+)\s+Client\
Domain:\t(?<cli entDomain>[\w
_-]+)\s+Client\ Logon\
ID:\t(?<clientL ogonId>[\d(),A-Fa-fx]+)\s+Accesses:\ t(?:(?<accesses >.+)
\s+)+?^(?:
\t)\s+Privilege s:\t(?<privileg es>[\w -_]+)\s+Restricted \ Sid\
Count:\t(?<rest rictedSidCount> \d+)\s+Access\
Mask:\t(?<acces sMask>[\dx]+)
"Wes" <ne********@NOS PAMpuzzleware.n et> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello Ben,

try:
foreach(Match m in Regex.Matches(l og, expression)
{
string access = m.Groups["accesses"].Value;
//write that access
}
Note: I have compiled or tested this it is from the top of my head.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/
Hey,

I have only been playing with regular expressions for some time. I
am working on some code that parses and object 560 event log. I
have created two expressions the first one which works okay is for
the actual csv of each log. The second one parses out the
description of the log. My problem is with the accesses section of
the description.

How do I parse multiple groups that have the same name. When I do a
for each through the groups I get the first value for each.

Snippet:
-----------------------------------------------
expression:
Accesses:\t(?:( ?<accesses>.+)\ s+)+?^(?: \t)
log section:
Accesses: READ_CONTROL
SYNCHRONIZE
ReadData (or ListDirectory)
ReadEA
ReadAttributes
Privileges: -
I would like to do something like

Match m = Regex.Match(log , expression);
foreach(string access in m.Groups["accesses"])
{
//write that access
}
Is this possible?
PS. I am using "The Regulator" for testing and it is successfully
parsing the Accesses in to groups.

Also, I have tried:
Match m = Regex.Match(log , expression);
foreach(string access in m.Groups)
{
// write access
}
it successfully matches 5 groups but the all equal to READ_CONTROL


Nov 16 '05 #5

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

Similar topics

3
1839
by: dmbkiwi | last post by:
I have a problem. I have written a python based theme for a linux app called superkaramba, which is effectively an engine for desktop applets that utilises python as its theming language. The script basically parses weather websites, and displays the info in a visually appealing way. A couple of other people have contributed code to this project, particularly relating to the parsing of the websites. Unfortunately, it is not parsing...
1
4184
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
1
287
by: Picho | last post by:
Hi all, first of all, does anyone know of a newsgroup dedicated for regular expressions? second - my problem: I have a string that represents a formula of the format: "formula(...)" the formula itself can contain other formula expressions like "Calc(...)", "Assign(...)" etc
3
1653
by: cjl | last post by:
Hey all: Given the following code: var ct_series = var cr_series = function preload() { for ( parm in window )
0
802
by: Brent Hoskisson | last post by:
I am writing a batch program for locating hyperlinks in HTML files. I thought I could use regular expressions to search for "<a HREF.*</a>" but this returns only one match from the beginning of the first hyperlink to the end of the last hyperlink. Is there a switch I am missing to have it return each hyperlink separately. Or is my regular expression wrong? How can I return each hyperlink individually Thank Brent
3
2551
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the regular expressions are correct as I got them from regexlib.com and tested them in the Regulator and Expresso. The problem is I tested this function with a file that contains a string
5
2112
by: basm101 | last post by:
Hi, I am trying to match a string like this: test (AB12 A) including the brackets. So far, I have this code: Pattern p = Pattern.compile("+/s+\\({2}{2}/s+{1}\\)"); Matcher m = p.matcher(string to match in here); boolean b = m.matches(); if(b){
5
8785
by: mikko.n | last post by:
I have recently been experimenting with GNU C library regular expression functions and noticed a problem with pattern matching. It seems to recognize only the first match but ignoring the rest of them. An example: mikko.c: ----- #include <stdio.h> #include <regex.h>
0
1134
by: Medwar19 | last post by:
Hi, Is it possible to used named groups in VBAs version of Regular Expressions (Regexp) Example match groups for extracting dates from strings: (?:(\d{2})\.(\d{2})\.(\d{4})\s(\d{2}):(\d{2}):(\d{2}))|(?:(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}) will returns DD.MM.YYYY or YYYY-MM-DD in submatch groups but the ordering is mixed up depending on the formatting.
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
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 we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.