[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Regular Expressions in C#

Posted on 2013-11-12
2
Medium Priority
?
458 Views
Last Modified: 2013-11-12
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
0
Comment
Question by:JamesNT
[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 Comments
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 2000 total points
ID: 39642386
Dealing with the string

DMG\*D8%~NM1\*PR\*2\*%PI\*DNC00~
where you want the %'s to match anything, you simply replace % with .*?

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

Open in new window

0
 

Author Comment

by:JamesNT
ID: 39642674
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

649 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