Solved

C# Regex Help

Posted on 2013-10-29
2
339 Views
Last Modified: 2013-11-16
Hi,

Can I get some help with a regex code for C#.

Here is my starting line of text.

<![LOG[==========[ ccmsetup started in process 3172 ]==========]LOG]!><time="14:32:31.717-600" date="07-29-2013" component="ccmsetup" context="" type="1" thread="908" file="ccmsetup.cpp:9100">==========[ ccmsetup started in process 3172 ]==========]LOG]!><time="14:32:31.717-600" date="07-29-2013" component="ccmsetup" context="" type="1" thread="908" file="ccmsetup.cpp:9100">

Open in new window


I want to capture the following fields.

<![LOG[Data in here]LOG]!>

So the first captured field would be:

==========[ ccmsetup started in process 3172 ]==========

The next field the time:  14:32:31.717-600

the date:

07-29-2013

component:

ccmsetup

and finally the thread:

908

And also have this match over multiple lines so I can read the whole file into one string and have it parse it all in one hit.

Thanks,

Ward.
0
Comment
Question by:whorsfall
2 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 39608472
try this

\<\!\[log(.+?)(?:\]log\]\!\>)

Open in new window

HTH

Ivo Stoykov
0
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 500 total points
ID: 39609538
This regex seemed to work well for me, though it trips up on the 'type' attrib(because of the "" before it); however if you don't care about anything after 'thread', then you should be set! :-)

(\w+)?=\"?(.+?)(?=\]log|")

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What can cause the styling on a .NET site to not be found? 17 29
Cant save 3D 4 23
.NET 2008 VB and C# 6 39
need to convert function to c# 5 31
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question