Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# regular Expression IUssue

Posted on 2009-07-01
4
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 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