Solved

c# regular Expression IUssue

Posted on 2009-07-01
4
297 Views
Last Modified: 2012-05-07
Hi all,  I have a hipaa file with contains multiple ISA headeras in it.  I am using regex to split the contents of the file into two distinct files.....

I got this to work using the following Regex Pattern: @"ISA\*00\*"
now my issue is I want to keep the original ISA*00* in the output results.   Ive tried several variations and just cannot seem to get it to work.  Can csomeone be so kind as to lend me a hand...preferabble with a bit of an explanation?

Thanks!

I got this to work using the following Regex Pattern: @"ISA\*00\*"
now my issue is I want to keep the original ISA*00* in the output results.   Ive tried several variations and just cannot seem to get it to work.  Can csomeone be so kind as to lend me a hand...preferabble with a bit of an explanation?
 
Thanks!

Open in new window

0
Comment
Question by:Greg85374
  • 2
4 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24759083
Looks like you made an accidental copy and paste error with your question. Did you mean to paste a piece of code instead of the same text as your q.?

I don't know much about HIPAA so if this is not what you want, please update with some more info on what strings should be changed into what other strings and by what rules.

My understanding is that you split it correctly, but that you need the captured string back in the splits. Since the split expression is always in the middle of two split parts, you'll have to decide yourself whether you want it in the first or the second part.

Your code is probably in a loop, to help you with placing it in the right context, can you show a relevant bit of your code?

// your split, something like this
string [] result = Regex.Split(inputString, @"ISA\*00\*");
// add to first part
string firstPart = result[0] + "ISA*00*";
// or prepend to second part
string secondPart = "ISA*00*" + result[1];

Open in new window

0
 

Author Comment

by:Greg85374
ID: 24763899
Thanks for the reply Abel...I know I can hard code the value back in but this is not really an option as this is a shared method.  I also know I can Use Match[0] and loop through the result set placing the match value in front of each result...I think this might be too much overhead for the rest of the program I am writing,  I was truly hoping for a way to tell Regex to keep the value which we are splitting on.  For Example  @"(ISA\*00\*)" will keep my ISA*00* but buts the results on two lines instead of one.  I also know in Perl you can do something like |- but I am not sure how to do this in .Net.


Any help would be highly appreciated.
0
 
LVL 39

Accepted Solution

by:
abel earned 250 total points
ID: 24763995
I figured something like that, but I didn't know your level and what your context was (also, you said "Beginner on Subject", which I interpret as, well, beginner... ;-)

The Split doesn't work the way you want, I can't change its semantics. Looping through the match collection is almost as speedy as Split: the regular expression is applied once and all variables for the Match collection are set. Retrieving those values is instantaneous and will not add to the overhead.

If you need extra speed, you can gain speed up (sometimes more then 2 times) by compiling the regex. You can speed up even more by compiling the regex in an assembly. But before we dive into such optimizations, let's try to have this first part done.

Do you need help looping through the match collection and getting the necessary parts for the split?

-- Abel --
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection String 16 57
Wav problem 4 26
Sent email using Shared Mailbox from outlook in C# 5 24
Problem!!! 8 33
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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