Solved

c# regular Expression IUssue

Posted on 2009-07-01
4
296 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

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

Suggested Solutions

Title # Comments Views Activity
Host asp.net pages 5 24
C# HTTP GET method sample code 3 37
how to read json value 2 27
Facial recognition to look through the whole database for a person 3 39
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

948 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

22 Experts available now in Live!

Get 1:1 Help Now