Link to home
Start Free TrialLog in
Avatar of JamesNT
JamesNT

asked on

Regular Expressions in C#

I have the following string:

DMG*D8*19481101*M~NM1*PR*2*EDS/MEDICAID*****PI*DNC00~

I need to find certain matches of that string.  Here is what I have tried:

string sPattern = @"DMG\*D8%~NM1\*PR\*2\*%PI\*DNC00~";

The issue is that, for example, the 19481101 could be a different number.  I don't care about that, nor do I care about the EDS/MEDICAID.  Those parts can change and it's fine.  In my pattern above, the parts I don't care about are denoted by a % (I realize its not legal in C# I'm just using it for illustrative purposes).  What I'm attempting to do is match up the parts I have that are literal and tell Regex that the parts denoted by % can by anything, I don't care, just ignore them.  By the way, this is all inside a text file (I'm looking for one part out of possible thousands of characters).  

Suggestions?

JamesNT
ASKER CERTIFIED SOLUTION
Avatar of Derek Jensen
Derek Jensen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JamesNT
JamesNT

ASKER

So that's all there was to it!  Once I went back and read the MSDN docs, it made perfect sense.  I guess I just needed to see it one time.

JamesNT