Solved

c# regular Expression IUssue

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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