Solved

C# Regex Help

Posted on 2013-10-29
2
328 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…

867 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

25 Experts available now in Live!

Get 1:1 Help Now