Solved

C# Regex Help

Posted on 2013-10-29
2
323 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
Comment Utility
try this

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

Open in new window

HTH

Ivo Stoykov
0
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now