Solved

c# regular Expression IUssue

Posted on 2009-07-01
4
295 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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.

744 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

18 Experts available now in Live!

Get 1:1 Help Now